Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 8, 2008, 02:22 PM   #1
maui24
macrumors newbie
 
Join Date: Nov 2008
UIButton to UITableView

Hi, I have been trying to figure this out for days... If anyone could give me some guidance it would be greatly appreciated. I created a simple drill down similar to the simple drill down code on the apple site. <https://developer.apple.com/iphone/library/samplecode/SimpleDrillDown/index.html> Everything works perfect except now I am trying to have a UIButton on a new first view link to the drilled down view. I am not sure if this is even possible. Here is the code for the detail view controller that works from the table view.

So instead of the clicking the first row and getting the information you would click buttton 1 and get the information, and instead of second row and getting the informaion you would click button 2 and so on... I hope this makes sense. Thanks...



#import "DetailViewController.h"


@implementation DetailViewController

@synthesize detailItem;


- (void)viewWillAppearBOOL)animated {
// Update the view with current data before it is displayed
[super viewWillAppear:animated];

// Scroll the table view to the top before it appears
[self.tableView reloadData];
[self.tableView setContentOffset:CGPointZero animated:NO];
self.title = [(NSDictionary *)detailItem objectForKey:@"title"];
}


// Standard table view data source and delegate methods

- (NSInteger)numberOfSectionsInTableViewUITableView *)tableView {
// There are three sections, for characters, genre, and date, in that order
return 3;
}


- (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section {

NSInteger rows = 0;
switch (section) {
case 0:
case 1:
// For genre and date there is just one row
rows = 1;
break;
case 2:
// For the characters section, there are as many rows as there are characters
rows = [[detailItem objectForKey:@"mainCharacters"] count];
break;
default:
break;
}
return rows;
}


- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"tvc";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

// Cache a date formatter to create a string representation of the date object
static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy"];
}

// Set the text in the cell for the section/row

NSString *cellText = nil;

switch (indexPath.section) {
case 0:
cellText = [dateFormatter stringFromDate:[detailItem objectForKey:@"date"]];
break;
case 1:
cellText = [detailItem objectForKey:@"genre"];
break;
case 2:
cellText = [(NSArray *)[detailItem objectForKey:@"mainCharacters"] objectAtIndex:indexPath.row];
break;
default:
break;
}

cell.text = cellText;
return cell;
}


/*
Provide section titles
HIG note: In this case, since the content of each section is obvious, there's probably no need to provide a title, but the code is useful for illustration.
*/
- (NSString *)tableViewUITableView *)tableView titleForHeaderInSectionNSInteger)section {

NSString *title = nil;
switch (section) {
case 0:
title = NSLocalizedString(@"Date", @"Date section title");
break;
case 1:
title = NSLocalizedString(@"Genre", @"Genre section title");
break;
case 2:
title = NSLocalizedString(@"Main Characters", @"Main Characters section title");
break;
default:
break;
}
return title;
}


@end
maui24 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
CGAffineTransformMakeTranslation and UIButton's titleLabel dantastic iPhone/iPad Programming 1 May 2, 2014 10:30 AM
iPad: Superclass UIButton Kevvaere iOS 6 1 Feb 26, 2014 06:42 AM
Resolved: Showing Badge on UIButton RagingGoat iPhone/iPad Programming 1 Feb 18, 2014 12:12 PM
Gesture recognizer interferes with UIButton twelveoclock iPhone/iPad Programming 1 Aug 2, 2013 01:01 PM
Weird Distortion of UIButton IDMah iPhone/iPad Programming 4 Dec 22, 2012 12:29 PM

Forum Jump

All times are GMT -5. The time now is 11:57 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC