Populating a UITableView from arrays

前端 未结 3 2011
臣服心动
臣服心动 2021-02-11 02:31

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         


        
相关标签:
3条回答
  • 2021-02-11 02:52
        - (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 ..*/
    
    }
    
    0 讨论(0)
  • 2021-02-11 02:56

    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

    • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    0 讨论(0)
  • 2021-02-11 03:03

    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.)

    0 讨论(0)
提交回复
热议问题