English 中文(简体)
抵达第17位顶楼时坠毁
原标题:App crashes when reaching 17th uitableviewcell

我写了一封信,从网上取出一个.子,把它分成两个层面(基本上就是这样)。 该公司实际上为每个部件配备一架NSArray,然后在可转让的电文中显示每个NSArray(通过使用分站装载每个NSArray)。

Anyways, once I scroll down to the 17th cell (index of 16) the app crashes...

UITableView应当有483个囚室(用于测试目的),但我似乎可以把第16个囚室推向过去,而没有坠毁。

Edit to post code and error:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[[tableView layer] setCornerRadius:3.0];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"identifier"]autorelease];
}

NSInteger artistIndex = 1;
NSInteger albumIndex = 3;
NSInteger dateIndex = 6;
NSInteger imageIndex = 5;

// ARTIST
CGRect frame = CGRectMake(59, 11, 244, 13);
UILabel *label = [[UILabel alloc]initWithFrame:frame];
label.font = [UIFont boldSystemFontOfSize:13];
label.textColor = [UIColor blackColor];
label.text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:artistIndex];
[cell addSubview:label];

// ALBUM (more like description...
frame = CGRectMake(60, 30, 244, 11);
label = [[UILabel alloc]initWithFrame:frame];
label.font = [UIFont boldSystemFontOfSize:11];
label.textColor = [UIColor darkGrayColor];
label.text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:albumIndex];
[cell addSubview:label];

// DATE
frame = CGRectMake(59, 49, 244, 10);
label = [[UILabel alloc]initWithFrame:frame];
label.font = [UIFont fontWithName:@"Helvetica" size:10.0];
label.textColor = [UIColor darkGrayColor];
label.textAlignment = UITextAlignmentRight;
label.text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:dateIndex];
[cell addSubview:label];

// IMAGE
NSString *urlString = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:imageIndex];
NSData *urlData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]];
UIImage *myImage = [[UIImage alloc]initWithData:urlData];
UIImageView *myImageView = [[UIImageView alloc] init];
myImageView.image = myImage;
myImageView.frame = CGRectMake(8,9,44,44);
[myImageView.layer setMasksToBounds:YES];
[myImageView.layer setCornerRadius:3.0];
[[cell contentView] addSubview:myImageView];

[urlData release];
[myImage release];
[myImageView release];
[label release];

return cell;

NOTE:我觉得,这部法典非常好...... 如果你提出清理的建议,我很想知道。

And here s the error message:

∗∗∗ 因无专业例外而终止妊娠:* - [NSMutable Array ObjectAtIndex:]:指数6超出约束范围 [0 。 3)

最佳回答

我的猜测是,你以及像你这样的其他人会倒退。

label.text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:artistIndex];

Try,

label.text = [[musicList.list objectAtIndex:artistIndex] objectAtIndex:indexPath.row];

在我的经验中,处理客观的两维阵列有时会令人困惑。 特别是在使用<条码>可调通时。

我感觉到的是,这是正确的。

NSInteger artistIndex = 1;
NSInteger albumIndex = 3;
NSInteger dateIndex = 6;
NSInteger imageIndex = 5;

<代码>1 + 3 + 6 + 5 = 15,另有一个,即16,是你坠毁的准确指数。

问题回答

You need to post code for your cellForRowAtIndexpath. You also need to post the console message you get when the crash occurs.

尽管如此,这还是像你的行动一样,使第17个牢房陷入坠毁。 从EXC_BAD_ACCESS到通过国家安全记录员的错误论点,可能没有任何东西。

这象一个简单的错误,可以确定。 张贴你的代码和错误信息。





相关问题
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, ...

热门标签