2011-10-02 27 views
0

的帮助为什么indexPath.Row总是返回0 ???在下面的方法中需要NSIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 

    // Configure the cell. 
    [cell.textLabel setText:[mainItems objectAtIndex:indexPath.row]]; 
    return cell; 
} 

mainItems是NSMutableArray的,有5个项目( “项目1”, “项目2”,...)的View也获得5项......但他们都 “项目1”,而不是项目1,第2项...

我做错了什么?

回答

3

我的猜测是你在-numberOfSectionsInTableView的实现中返回了错误的值,并且表视图要求你输入5个部分的第0行。

表格视图有部分,每个部分都有行。许多表视图只有一个部分,但该部分中有许多行。这听起来像你有一个部分,5行。确保你在每一个返回正确的值:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
+0

tks很多...事实上,我设置部分= [mainItens计数],而不是项目!我会尽快标记为正确的! – Leonardo