how to return two custom uitableviewcells
-
Hi just trying to figure out how to load two different custom uitableviewcells into two different sections on my uitableview... Just not sure on how to proceed... here is the code I have currently - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //Registration Button static NSString *CellIdentifier = @"CustomRegCell"; static NSString *CellNib = @"LogInCustomCell"; UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil]; cell = (UITableViewCell *)[nib objectAtIndex:0]; } return cell; } /////// NEW ATTEMPT.... :( if you could call it that.. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { //Registration Button static NSString *CellIdentifier = @"CustomRegCell"; static NSString *CellNib = @"LogInCustomCell"; UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil]; cell = (UITableViewCell *)[nib objectAtIndex:0]; } return cell; } else if (indexPath.section == 1) { //Registration Button static NSString *CellButtonIdentifier = @"CustomButtonCell"; static NSString *CellButtonNib = @"LogInCustomCell"; UITableViewCell *cellButton = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellButtonIdentifier]; if (cellButton == nil) { NSArray *nibButton = [[NSBundle mainBundle] loadNibNamed:CellButtonNib owner:self options:nil]; cellButton = (UITableViewCell *)[nibButton objectAtIndex:0]; } return cellButton; } return nil; }
-
Answer:
Use the section property of the indexPath variable: if (indexPath.section == 0) { // do this } else if (indexPath.section == 1) { // do that } The section number is based on the order in which they appear. The first section you want to show in the tableView will be 0, and so on.
tinhead at Stack Overflow Visit the source
Related Q & A:
- How to return a value from .ashx file to javascript in a variable?Best solution by forums.asp.net
- How to return the response from an asynchronous function?Best solution by Stack Overflow
- How to return result from ajax call synchronously?Best solution by Stack Overflow
- How to return result of function?Best solution by Stack Overflow
- How to return multiple objects of a specific library in R?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.