在我的应用程序中,我正在使用数组打印图像中的图像查看目前在表视图。该数组用于存储我在文本框中输入的组件,每个用空格隔开例如我进入男孩女孩则数组将男孩存储为一个对象,女孩为其他,然后搜索each.following的图片是我的代码: -EXC_BAD_ACCESS在xcode
-(IBAction)Click
{
//count = [youSaid.text intValue];
//count=1;
//NSArray *sub= [youSaid.text componentsSeparatedByString:@" "];
j=1;
sentence=[youSaid.text componentsSeparatedByString:@" "];
//[substring addObject:youSaid.text];
[tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];
UIImageView * imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 80, 80)] autorelease];
UIImageView * imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,80, 80)] autorelease];
UIImageView * imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake(205,4, 80, 80)] autorelease];
UIImageView * imageView4 = [[[UIImageView alloc] initWithFrame:CGRectMake(295,4, 80, 80)] autorelease];
imageView1.tag = j;
imageView2.tag = j+1;
imageView3.tag = j+2;
imageView4.tag = j+3;
//imageView1.tag=t;
// t++;
// imageView2.tag=t;
// t++;
// imageView3.tag=t;
// t++;
// imageView4.tag=t;
// t++;
[cell.contentView addSubview:imageView1];
[cell.contentView addSubview:imageView2];
[cell.contentView addSubview:imageView3];
[cell.contentView addSubview:imageView4];
}
//[sentence addObject:@"BLINK"];
// UIImageView * imageView;
//for (int i = 1; i <= j; i++) {
for (int i = 1; i <= j; i++) {
imageView = (UIImageView *)[cell.contentView viewWithTag:i];
//button = (UIButton *)[cell.contentView viewWithTag:i];
imageView.image = nil;
//[button setImage:nil forState:UIControlStateNormal];
}
int photosInRow;
//NSLog([NSString stringWithFormat:@"%d", [sentence count]]);
if ((indexPath.row < [tableView numberOfRowsInSection:indexPath.section] - 1)
|| ([sentence count] % 4 == 0)) {
photosInRow = 4;
} else {
photosInRow = [sentence count] % 4;
}
// for (int i = 1; i <= photosInRow; i++)
for (int i = 1; i <=[sentence count]; i++){
imageView = (UIImageView *)[cell.contentView viewWithTag:i];
//button = (UIButton *)[cell.contentView viewWithTag:i];
[self setImage1:imageView];
//[self setImage1:button];
//imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", i]];
//imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", youSaid.text]];
//imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"1.png"]];
}
//cell.textLabel.text = [autoCompleteArray objectAtIndex:indexPath.row];
return cell;
}
我得到EXC_BAD_ACCESS,当我访问其他方法我的数组这是什么原因,请帮忙。
感谢, 克里斯蒂
是的它的工作,你可以给我rreason另外我的意思是我ahev保留在.h fil – Christina
因为componentsSeparatedByString返回一个自动释放对象,没有保留它然后它被释放。您稍后尝试访问它,并且BOOOOOOM! –
非常感谢.great – Christina