English 中文(简体)
Weird conduct of indexPath.section in “cellForRowAtIndexPath:”
原标题:Weird behavior of indexPath.section in "cellForRowAtIndexPath:"

我对<代码>indexPath.section在cellForRowAtIndexPath:方法上存在 problem问题。

我有一份分组的表,有4节和Im试图对第3节适用“海关编码”的,但并未奏效。

当我尝试if(indexPath.section=0){...}时,该代码(和section==1section=2,但该编码未能在section=3上签字。

我不知道为什么没有意义。 是否有这样的(奇怪)问题?

当我尝试<代码>if(indexPath.row=0){......}时,它就为所有4个章节开展工作。

我的法典如下:

//ViewController.h
import "DirectionsTableViewCell.h"
DirectionsTableViewCell *directionsCell; // customized UITableViewCell

//ViewController.m
if (indexPath.section==3) {
        static NSString *CellIdentifier = @"directionsCell";

        DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if(cell == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"DirectionsTableViewCell" owner:self options:nil];
            cell = directionsCell;
        }

        return cell;
    }
    else {
        static NSString *CellIdentifier = @"defaultCell";

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

        cell.textLabel.text = @"Test";

        return cell;
    }

www.un.org/Depts/DGACM/index_spanish.htm

www.un.org/Depts/DGACM/index_spanish.htm 问题得到解决!

我仅添加if(indexPath.row),并作罚款。

最后,请:

if(indexPath.section==3) {
   if(indexPath.row) {
      static NSString *CellIdentifier = @"directionsCell";

      DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if(cell == nil) {
          [[NSBundle mainBundle] loadNibNamed:@"DirectionsTableViewCell" owner:self options:nil];
          cell = directionsCell;
      }

      return cell;
   }
}
最佳回答

您也从未在<条码>内发出指示。

在你法典的这一部分:

DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if(cell == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"DirectionsTableViewCell" owner:self options:nil];
            cell = directionsCell;
        }

您从未分配过一个类型的<代码>DirectionsTableViewCell,以便日后再使用。 我也通知你,有一份名为<代码>directionsCell的单体编码<>。 除非您重新分配和在其他地方设立,cell = 方向Cell 页: 1

改写这一法典,看它是否发挥作用:

static NSString *CellIdentifier = @"directionsCell";

directionsCell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(directionsCell == nil) {
        directionsCell = [[DirectionsTableViewCell alloc] init]; //Or whatever your initializer is
    }

    return directionsCell;
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签