I need help with the following code i am using hpple to parse html. and i need help utilizing the data.
-(void) whatever{
NSData *htmlData = [[NSString stringWit
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [titles count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
cell.textLabel.text = [titles objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
/* here pop up Your subview with corresponding value from the array with array index indexpath.row ..*/
}
First you have to set UITableViewDelegate and UITableViewDatasource in .h file where you are creating tableview and declare an NSarray to store the table values,and in .m file of viedidload function you need to intialise the array with objects (arr_name=[NSArray alloc]initwith Objects:@"one",@"two",nil) and you have to place these three methods
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
As a general approach, you simply need to set the relevant controller class as a delegate for the UITableView in question and then implement the following methods:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
However, I'd recommend reading Apple's Table View Programming guide - it'll elucidate a lot more than a simple code sample, and is reasonably easy to follow.
Once you've done that, if you're still after sample code simply download one of the projects within the "Related sample code" section of the UITableView Class reference. (If you do this within Apple's doc viewer in Xcode it automates the download, etc. and will bring up the project in Xcode for you.)