- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Book1*aBook;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell1.png"]];
[cell setBackgroundView:img];
[img release];
}
UIImage *image = [UIImage imageNamed:@"arrow.png"] ;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
if(indexPath.section == 0)
{
aBook=[appDelegate.books1 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 1)
{
aBook=[appDelegate.books2 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 2)
{
aBook=[appDelegate.books3 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 3)
{
aBook=[appDelegate.books4 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 4)
{
aBook=[appDelegate.books5 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 5)
{
aBook=[appDelegate.books6 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 6)
{
aBook=[appDelegate.books7 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 7)
{
aBook=[appDelegate.books8 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 8)
{
aBook=[appDelegate.books9 objectAtIndex:indexPath.row];
}
else if(indexPath.section == 9)
{
aBook=[appDelegate.books10 objectAtIndex:indexPath.row];
}
cell.text = aBook.municipality;
cell.detailTextLabel.text=aBook.title;
eventId = [NSString stringWithFormat:@"%d", aBook.eventId];
affectedDate = [NSString stringWithFormat:@"%d", aBook.affecteddate];
cell.textLabel.backgroundColor=[UIColor clearColor];
cell.backgroundColor=[UIColor clearColor];
self.tableView.backgroundColor=[UIColor clearColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)checkButtonTapped:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil)
{
[self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString*myid=eventId;
NSString*date=affectedDate;
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
dvController.eventId=myid;
dvController.affectedDate=date;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
我使用这种方式将数据发送到详细视图控制器,但它提供了异常
答案 0 :(得分:0)
尝试在界面构建器中检查你的nib是否存在错误/警告 - 可能是你发错了。