Using this post, I am going to explain "working with multiple data-sources in uitableview ".
Expected output of this tutorial is demonstrated by following images.
Step 1: load data into your arrays (if you are fetching from XML/Web do that, I have implemented static here)
-(Void) viewdidload
{
[Super viewdidload];
Self. arone = [nsarray arraywithobjects: @ "Sagar", @ "Amit", @ "nimit", @ "Paresh", @ "Rakesh", @ "Yogesh", nil];
Self. artwo = [nsarray arraywithobjects: @ "supreeth", @ "deepthy", @ "ankit", @ "Sandeep", @ "gomathy", nil];
[Self. tableview reloaddata];
}
Step 2: Implement coding in such a way that handles multiple data-sources. It means place conditional coding as following example
-(Uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath
{
Static nsstring * cellidentifier = @ "cell ";
Uitableviewcell * cell = [self. tableview dequeuereusablecellwithidentifier: cellidentifier];
If (cell = nil ){
Cell = [[[uitableviewcell alloc] initwithstyle: uitableviewcellstyledefault reuseidentifier: cellidentifier] autorelease];
}
Cell. textlabel. Text = [(self. btntapped. Selected )? Self. artwo: Self. arone objectatindex: indexpath. Row];
Return cell;
} Step 3: Add a connection to your button or whatever control that you are using.
-(Ibaction) btntitle :( ID) sender {
Self. btntapped. Selected =! Self. btntapped. selected;
[Self. tableview reloaddata];
}