iphone - uitableview 行呈现奇怪的行为

标签 iphone ios ipad uitableview

我想要两个 create 2 sections uitableview 所以我做了以下代码

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    NSLog(@" I entered numberOfSectionsInTableView");
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {          
    if (section = 0 ) {  
        1;   
    }
    else {
        9; 
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NSLog(@" I entered cellForRowAtIndexPath");
    NSLog(@"the Caf files count is : %d",[self.CafFileList count] );
    NSLog(@" the txt file %d",[self.TXTFileList count] );
    if (indexPath.section == 0 ) { // Enter here twice , even I say it contain only one row
        NSLog(@"////////////////////////Section 0 %d" , [indexPath row] );  
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }   
        [[cell textLabel] setText:[self.TXTFileList objectAtIndex:[indexPath row] ]   ];    
        return cell;    
    }
    else if (indexPath.section == 0 && indexPath.row < [self.TXTFileList count]  ){
        NSLog(@"////////////////////////Section 1 %d" , [indexPath row] );
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
        [[cell textLabel] setText:[self.CafFileList objectAtIndex:[indexPath row]]   ];
        return cell;
    }
}

问题是它在这里输入了两次,即使我说它只包含一行

if (indexPath.section == 0 ) {   

想知道怎么解决吗

最佳答案

您不返回 numberOfRowsInSection 中的行号,您只是输入一个数字,但不返回任何内容。

此外,

    if (section = 0 ) {  

设置 section 为 0,你想使用 == 运算符。

关于iphone - uitableview 行呈现奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9397269/

相关文章:

iphone - 如何让我的 iPhone 应用程序在启动时显示特定屏幕?

iphone - 使用 ffmpeg 覆盖视频 - 我想添加视频旋转代码并重写现有文件..我该怎么做?

ios - DidSelectRowAtIndexPath 不响应搜索显示 Controller

ios - 旧的 RPG 滚动文本,但用(点点点)分解文本 block

iphone - 简单的iCloud实现

iphone - 如何从其他地方调用按钮 Clicked 方法

ios - 如何向 UITableView 添加边距

objective-c - 一个 Controller 来统治他们

iphone - 我们可以使用 gamecenter 在 iPhone 和 iPad 之间在线玩游戏吗?

cocoa - 这是来自 iPad 的格式错误的 http 请求吗?它会杀死 Node.js 多部分解析器