how to pass section table views data in detail view
- (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 obj开发者_如何学PythonectAtIndex: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];
}
I am using this way to send data to detail view controller but it gives exception
try checking your nib in interface builder for errors/warnings - it maybe that you have something wired up wrong.
精彩评论