开发者

How can i add objects into UITableView?

开发者 https://www.devze.com 2023-01-28 22:33 出处:网络
How can i add objects into UITabl开发者_开发知识库eView?You have to first take IBOutlet Object of UITableView in interface file and then bind it using interface builder. Set delegate and data source o

How can i add objects into UITabl开发者_开发知识库eView?


You have to first take IBOutlet Object of UITableView in interface file and then bind it using interface builder. Set delegate and data source of UITableView in the interface builder property.

And do the following coding in your project.

In .h file:

@interface RootViewController : UITableViewController<UITableViewDelegate,UITableViewDataSource> {

    IBOutlet UITableView *tblView;
}

In .m file:

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return n;// n for number of row.
}

// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.

    return cell;
}


Implement the UITableViewDataSource delegate methods.

Also check out the Table View Programming Guide.


Tableviews are populated by datasources, datasources are often an array of objects.

I suggest you look through some tutorials on tableviews and also delegate methods.

http://icodeblog.com/2008/08/08/iphone-programming-tutorial-populating-uitableview-with-an-nsarray/

icodeblog is a fantastic website for beginners.

0

精彩评论

暂无评论...
验证码 换一张
取 消