[英]EXC_BAD_ACCESS in xcode
在我的應用程序中,我使用數組打印圖像中的圖像視圖存在於表視圖中。數組用於存儲我在文本框中輸入的組件,每個組件用空格分隔,例如我輸入了Boy Girl然后是數組將Boy作為一個對象存儲,將Girl存儲為其他對象,然后搜索每個圖像。以下是我的代碼: -
-(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。這是什么colud。請幫忙。
謝謝,克里斯蒂
添加保留....
sentence=[youSaid.text componentsSeparatedByString:@" "];
[sentence retain];
如果sentence
是具有retain
屬性的class屬性,則使用點表示法語法
self.sentence = [youSaid.text componentsSeparatedByString:@" "];
正確保留sentence
對象。 確保在dealloc
方法中釋放sentence
以避免內存泄漏。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.