ios - 单个 UITableView 中的多个 CustomCell

标签 ios cocoa-touch uitableview

试图在一个 uitableview 中获取多个自定义单元格,但目前它不起作用,它所做的只是使用第一个 if 语句 block 来设置单元格外观。 我应该怎么办? - 感谢您的回复,Daniel Ran

代码如下:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if(indexPath.row == 0) {

        //Facebook Tile//
        static NSString *FacebookCellID = @"FacebookCellID";
        FacebookTileCell *FacebookCell = (FacebookTileCell  *)[tableView dequeueReusableCellWithIdentifier:FacebookCellID];

        if (FacebookCell == nil) {

            NSString *XIBStringFacebookTile;
            XIBStringFacebookTile = @"FacebookTileCell";
            NSArray *FacebookTileArray = [[NSBundle mainBundle] loadNibNamed:XIBStringFacebookTile owner:self options:nil];

            NSUInteger FacebookInteger;
            FacebookInteger = 0;
            FacebookCell = [FacebookTileArray objectAtIndex:FacebookInteger];

            UIView *CellSelectedStyle = [[UIView alloc] init];

            UIColor *CellSelectedStyleColor = [UIColor FacebookColor];
            CellSelectedStyle.backgroundColor = CellSelectedStyleColor;

            [FacebookCell setBackgroundView:CellSelectedStyle];


        }

        return FacebookCell;
    }

    else if (indexPath.row == 1) {

    //Twitter Tile//
    static NSString *TwitterCellID = @"TwitterCellID";
    TwitterTileCell *TwitterCell = (TwitterTileCell  *)[tableView dequeueReusableCellWithIdentifier:TwitterCellID];

    if (TwitterCell == nil) {

        NSString *XIBStringTwitterTile;
        XIBStringTwitterTile = @"TwitterTileCell";
        NSArray *TwitterTileArray = [[NSBundle mainBundle] loadNibNamed:XIBStringTwitterTile owner:self options:nil];

        NSUInteger TwitterInteger;
        TwitterInteger = 0;
        TwitterCell = [TwitterTileArray objectAtIndex:TwitterInteger];

        UIView *CellSelectedStyle = [[UIView alloc] init];

        UIColor *CellSelectedStyleColor = [UIColor TwitterColor];
        CellSelectedStyle.backgroundColor = CellSelectedStyleColor;

        [TwitterCell setBackgroundView:CellSelectedStyle];


    }

    return TwitterCell;

    }


}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //refine algorithm//
    return self.view.frame.size.height/NumberofTiles;
    NSLog(@"Flexible Tile Height = %d", NumberofTiles);

    //imbed switch case statement later on//
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    //Just one section in FeedbackTableView//
    return NumberofTiles;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 1;

}

最佳答案

这是你的问题:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

你在这里说你只有一个单元格。

关于ios - 单个 UITableView 中的多个 CustomCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20792025/

相关文章:

iphone - 预定的 UILocalNotifications 是 iOS 设备备份的一部分吗?

ios - 如何让 UITableView 成为 UIView 的 subview ?

ios - UITableViewCell backgroundView 绘制矩形未被调用

ios - iOS:模拟器中的音频录制设置失败,但我的设备上没有?

iphone - 为什么 UINavigationController 的 toolbarItems 在 View 的其余部分之后刷新 4-5 秒?

ios - 如何在 iOS 13 的 UISegmentedControl 中更改段的颜色?

xcode - iPhone 崩溃可能与 NSUserDefaults 有关

ios - 如何重新加载UITableViewCell Objective C?

通过数据耳机端口的 iOS 数据

iphone - UITextView的每一行中的字符数是否相同?