Top Cells in my UItableView does not appear - ios

Here is my question:
I have uitableview with different sections and each section have many rows.
The problem is that when I run the app in iPad simulator my first five rows of section 0 in the UITableView does not appear unless I scroll up to see them then they get back to be not appeared after stop scrolling ?
PLEASE HELP .
Thanks in advance and happy coding.
Here is the implementation of Datasource Methods:1. number of sections:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
NSMutableArray *catarr = [[NSMutableArray alloc] init];
catarr= [d Category];
NSInteger length ;
length = [catarr count];
return length;
}
2.number of rows:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSMutableArray *catarr = [[NSMutableArray alloc] init];
catarr = [d Category];
NSInteger length ;
length = [catarr count];
NSInteger count ;
NSMutableArray *word;
for ( int i=0 ; i < length ; i++)
{
if (section == i )
{
NSString *str = [catarr objectAtIndex:i];
word = [[NSMutableArray alloc] init];
word = [d CatRowName:str];
count = [word count];
return count;
}
}
return 0 ;
}
3. cell at index path :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifer = #"Cell";
UITableViewCell *cell= [ tableView dequeueReusableCellWithIdentifier:CellIdentifer];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifer];
}
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
UILabel *label ;
label=(UILabel *)[cell viewWithTag:1];
NSString *value = [[mainArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
label.text = value;
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
label=(UILabel *)[cell viewWithTag:2];
NSString *value2 = [[mainArray2 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
label.text= value2;
NSString *value3 = [[mainArray3 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:value3];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
return cell;
}

Related

iOS how to display dictionary keys into table cells

I have a dictionary declared as "res". This "res" contains response of JSON data.
I did a valueforkey = "id" to retrieve out the list of id.
When I want to display each id into the tableview it turns out it only displays the same id repetively.
Here is my tableview:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [res count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableViews dequeueReusableCellWithIdentifier:#"cell"];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.numberOfLines = 0;
cell.textLabel.textColor =[UIColor blackColor];
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
for(int i = 0; i<res.count; i++)
cell.textLabel.text = [NSString stringWithFormat:#"ID: %#",[res valueForKey:#"id"]];
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] init];
return view;
}
When i NSLOG out the res with value "id" :
icon = [res valueForKey:#"id"];
NSLog(#"icon: %#", icon);
it shows:
icon: (
300122,
300228,
300235,
300272,
300265,
300242,
300198,
300135,
300282,
300255,
300245,
300248,
300185,
300118,
300275,
300295,
300005,
300062,
300068,
300055,
300095,
300008,
300018,
300015,
300058,
300012,
300085,
300038,
300105,
300002,
300072,
300022,
300025,
300028,
300035,
300258,
300088,
300262,
300128,
300215,
300142,
300078,
300205,
300315,
300238,
300302,
300232,
300285,
300132,
300102
)
Question is how do i display each id on each cell in the tableview?
Set an array of allKeys
NSArray *array = [NSArray arrayWithArray:[yourDictionary allKeys]];'
then just set your tableView dataSource using this array.
e.g
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableViews dequeueReusableCellWithIdentifier:#"cell"];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.numberOfLines = 0;
cell.textLabel.textColor =[UIColor blackColor];
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [NSString stringWithFormat:#"ID: %#",[array objectAtIndex:indexPath.row]];
return cell;
}
Replace numberOfRowsInSection with:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *arrIds = (NSArray *)[res valueForKey:#"id"];
return arrIds.count;
}
And replace
for(int i = 0; i<res.count; i++)
cell.textLabel.text = [NSString stringWithFormat:#"ID: %#",[res valueForKey:#"id"]];
with
NSArray *arrIds = (NSArray *)[res valueForKey:#"id"];
cell.textLabel.text = [NSString stringWithFormat:#"ID: %#",[arrIds objectAtIndex:indexPath.row]];
Store your #"id" values in one array as follows;
NSArray *icon = [res valueForKey:#"id"];
NSLog(#"icon: %#", icon);
Then use that array to display values in TableView cell as follows;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableViews dequeueReusableCellWithIdentifier:#"cell"];
cell.textLabel.text = [NSString stringWithFormat:#"ID: %#",[icon objectAtIndex:indexPath.row]];
return cell;
}
Replace line below
for(int i = 0; i<res.count; i++)
cell.textLabel.text = [NSString stringWithFormat:#"ID: %#",[res valueForKey:#"id"]];
with line
cell.textLabel.text = [NSString stringWithFormat:#"ID: %#",[[res valueForKey:#"id"] objectAtIndex:indexPath.row]];
your for loop logic is not correct to achieve the goal. We have tableView's default indexPath object to fetch current row in tableview, so fetch the value from your at the tableview's indexPath from your array.
in
ViewDidload{
NSArray * iconArray = [res allKeys];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableViews dequeueReusableCellWithIdentifier:#"cell"];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.numberOfLines = 0;
cell.textLabel.textColor =[UIColor blackColor];
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [NSString stringWithFormat:#"ID: %#",[iconArray objectAtIndex:indexPath.row]];
return cell;
}

Cell for row at indexpath only called once

I am parsing a json data and in that one of the field is an array if it has a content.But if it has no content it is simply a string "No result."
I am using the following code to parse it :
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
//URL is called.
if ([status isEqualToString:#"success"])
{
if ([[[json objectForKey:#"Items"] objectForKey:#"item_list"] isKindOfClass:[NSString class]])
{
_Label.text = [NSString stringWithFormat:#"0"];
ItemsArray = [[NSMutableArray alloc]init];
}
else
{
ItemsArray = [[json objectForKey:#"Items"] objectForKey:#"item_list"];
NSLog(#"%d",[ItemsArray count]);
float Amount = 0;
NSLog(#"%d",[ItemsArray count]);
if ([ItemsArray count]>0)
{
for (int i=0; i<[ItemsArray count]; i++)
{
NSMutableDictionary * temp3 = [ItemsArray objectAtIndex: i];
NSString * x = [temp3 objectForKey:#"final"];
Amount = Amount + [x floatValue];
}
Label.text = [NSString stringWithFormat:#"%.2f",BidAmount];
}
else
{
Label.text = [NSString stringWithFormat:#"0"];
}
}
[TableViewOutlet reloadData];
}
This works fine.
When the field returns string i face no problem.But when the field is an array,I am stuck.
After running the project for the first time it works fine even if the array count is more than 0.But from second time onwards the Cellforrowatindexpath method is not called even when array count is more than 0....
These are my codes:
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(#"%d",[ItemsArray count]);
return [ItemsArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.025];
NSDictionary *temp = [ItemsArray objectAtIndex:indexPath.row];
UILabel *ItemName = (UILabel *)[cell viewWithTag:1000];
ItemName.text = [temp objectForKey:#"title"];
UILabel *Cost = (UILabel *)[cell viewWithTag:1001];
Cost.text = [temp objectForKey:#"final"];
return cell;
}
Someone please help me
I think the issue is that you have not retained your ItemArray.
NSArray* array = [[json objectForKey:#"Items"] objectForKey:#"item_list"];
ItemsArray = [NSMutableArray alloc]]initWithArray:array];
Use this code snippet..hope it will work.

iOS: Section overlaps UITableView record

I am trying to display three sections (#"Accounts and Tasks", #"Life Events", #"More") and relevant content in an UITableView. I am creating a custom UILabel for each row and try to display text.
Here is my code below. My issue is, The third section instead of displaying third section contents "Social Media", #"About Hop, #"Settingsā€, it is showing some first section contents and overlapping the text.
Could someone guide me to solve this please?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSArray *arrTemp1 = [[NSArray alloc]initWithObjects:#"My Accounts",#"Transfers/Deposit",#"Pay Bills", #"Investment Center",#"Claims Center",#"Locators",#"Loan Calculator", nil];
NSArray *arrTemp2 = [[NSArray alloc]initWithObjects:#"Auto Circle",#"Home Circle",nil];
NSArray *arrTemp3 = [[NSArray alloc]initWithObjects:#"Social Media",#"About Hop", #"Settings", nil];
self.keys = [NSArray arrayWithObjects:#"Accounts and Tasks", #"Life Events", #"More", nil];
NSArray *values = [NSArray arrayWithObjects:arrTemp1, arrTemp2, arrTemp3, nil];
self.tableContents = [NSDictionary dictionaryWithObjects:values forKeys:keys];
NSLog(#"table %#",self.tableContents);
NSLog(#"table with Keys %#",[self.tableContents allKeys]);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [self.keys count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [self.keys objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
NSArray *listData =[self.tableContents objectForKey:[self.keys objectAtIndex:section]];
return [listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:[self.keys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if(cell == nil) {
NSLog(#"listData: %#", listData);
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(26, 4, 250, 30)];
label.text = [listData objectAtIndex:[indexPath row]];
label.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:label];
}
[cell setUserInteractionEnabled:YES];
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imv.image=[UIImage imageNamed:#"SettingsMore"];
[cell.contentView addSubview:imv];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
....
UILabel *label;
if(cell == nil) {
label = [[UILabel alloc] initWithFrame:CGRectMake(26, 4, 250, 30)];
label.tag = 8888;
label.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:label];
}
label = (UILabel *)[cell.contentView viewWithTag:8888];
label.text = [listData objectAtIndex:[indexPath row]];
}
If you set label.text in if(cell == nil), the text will not get updated on reusing the cell.

ios: NSMutableArray Count Prints Zero after adding object?

My project is based on parsing xml data and adding it to array and display in respectives views,now my problem is am parsing xml and adding those objects it to nsmutablearray as shown below:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
samplearray = [[NSMutableArray alloc]init];
xmlParserObject = [[NSXMLParser alloc] initWithData:webData];
[xmlParserObject setDelegate:self];
[xmlParserObject parse];
for (int i =0; i<[rssOutputData count]; i++) {
NewsList *log = [rssOutputData objectAtIndex:i];
feedid = log.id;
NSLog(#"%d",feedid);
Invit = log.newsletterdet;
NSLog(#"%#",Invit);
[samplearray addObject:log];
NSLog(#"Count Final %d",[self.samplearray count]);
}
[[self navigationController] tabBarItem].badgeValue = mycount2;
NSLog(#"%#",mycount2);
[tblView reloadData];
[connection release];
}
The Above prints Count Value as 2014-04-04 15:21:10.009 cftsversion1[3087:70b] Count Final 1
But when I call those Count in tableview methods, it prints 0 so I cannot load datas in tableview Here is the code I tried for tableview methods:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
return [samplearray count];Prints 0 here
NSLog(#"Count %d",[samplearray count]); Prints 0 here
if (section == 1)
return 1;
return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"eventCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
if (indexPath.section == 0)
{
NewsList *msglist = [samplearray objectAtIndex:indexPath.row];
cell.textLabel.text = msglist.newsletterdet;
NSLog(#"%#",msglist.newsletterdet);
NSInteger stat = msglist.readflag;
if ([[SingleTonClass sinlgeTon].colorArray2 containsObject:[NSString stringWithFormat:#"%d",indexPath.row]] || stat == 1) {
cell.textLabel.textColor = [UIColor redColor];
}
else{
cell.textLabel.textColor = [UIColor greenColor];
}
cell.backgroundColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if (indexPath.section == 1)
{
UIButton *viewmoreButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
viewmoreButton.frame = CGRectMake(200.0f, 5.0f, 80.0f, 30.0f);
[viewmoreButton setTitle:#"View More" forState:UIControlStateNormal];
[cell addSubview:viewmoreButton];
[viewmoreButton addTarget:self
action:#selector(viewMore:)
forControlEvents:UIControlEventTouchUpInside];
cell.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:viewmoreButton];
}
return cell;
}
When run the above tableview code section 0 is not at all loading because array count prints 0 only section 1 is loading please help me how to solve this issue Thanks in advance
Intialize sampleArray in ViewDidLoad
samplearray = [[NSMutableArray alloc]init]
Make sure [tblView reloadData] is working properly.Initialy table will be loaded before completion of connectionDidFinishLoading, so count will be 0. Only in reload the count increments.
I have doubt you are printing value in wrong way. Try to print it correctly first and update us:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
{
NSLog(#"Count %d",[samplearray count]);\\ Prints 0 here
return [samplearray count];\\Prints 0 here
}
else if (section == 1)
{
return 1;
}
return 0;
}
and declare your NSMutableArray in .h file like:
#property (nonatomic, strong) NSMutableArray *samplearray;

UITableView didSelectRowAtIndexPath pushes data loaded last from NSArray no matter which row is selected

I have a UITableView which is populated with some parsed JSON twitter data. The intent is to have the user select the a row, and have the data passed to a modalViewController, which in this case is a map displaying coordinate and annotation information.
In the debug console I can see the data loaded into each visible UITableViewCell, plus the first one off screen (last loaded). When I run the app, and attempt to select a row, no matter which row I select, the data from the last loaded cell is always the data passed to the modalViewController.
I have logged to ensure the correct row is selected (it is) but no matter which row is selected, the last data loaded is always the data that is pushed.
First the Data Source Methods
#pragma mark -
#pragma mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSUInteger count = [self.results count];
return count > 0 ? count : 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ResultCellIdentifier = #"ResultCell";
static NSString *LoadCellIdentifier = #"LoadingCell";
NSUInteger count = [self.results count];
if ((count == 0) && (indexPath.row == 0)) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LoadCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:LoadCellIdentifier];
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
if (self.connection) {
cell.textLabel.text = #"Loading...";
} else {
cell.textLabel.text = #"Not available";
}
return cell;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ResultCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:ResultCellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont systemFontOfSize:14.0];;
}
UIImage *image = [UIImage imageNamed:#"medicaltag.png"];
cell.imageView.image = image;
// Begin UITableCell Data Formatting
NSDictionary *tweet = [self.results objectAtIndex:indexPath.row];
NSString* tweetText = [tweet objectForKey:#"text"];
if ([tweetText rangeOfString:#" *** "].location !=NSNotFound) {
NSArray *textItems = [tweetText componentsSeparatedByString:#" *** "];
NSLog(#"%#", textItems);
callAddress = [textItems objectAtIndex:0];
callAddress = [callAddress stringByReplacingOccurrencesOfString:#" , " withString:#", "];
callType = [textItems objectAtIndex:1];
NSLog(#"%#", callType);
NSLog(#"%#", callAddress);
NSString *latitude = [textItems objectAtIndex:2];
NSString *latStringPt1 = [[NSString alloc] init];
NSString *latStringPt2 = [[NSString alloc] init];
NSString *longitude = [textItems objectAtIndex:3];
longitude = [longitude stringByReplacingOccurrencesOfString:#"- " withString:#"-"];
NSString *lonStringPt1 = [[NSString alloc] init];
NSString *lonStringPt2 = [[NSString alloc] init];
int latStringLen = [latitude length];
int lonStringLen = [longitude length];
NSLog(#"The value of integer num is %i", latStringLen);
latStringPt1 = [latitude substringWithRange:NSMakeRange(0,latStringLen-6)];
latStringPt2 = [latitude substringFromIndex:latStringLen-6];
combinedLatString = [latStringPt1 stringByAppendingString:#"."];
combinedLatString = [combinedLatString stringByAppendingString:latStringPt2];
lonStringPt1 = [longitude substringWithRange:NSMakeRange(0,lonStringLen-6)];
lonStringPt2 = [longitude substringFromIndex:lonStringLen-6];
combinedLonString = [lonStringPt1 stringByAppendingString:#"."];
combinedLonString = [combinedLonString stringByAppendingString:lonStringPt2];
NSLog(#"%#", combinedLatString);
NSLog(#"%#", combinedLonString);
}
cell.textLabel.text = [NSString stringWithFormat:#"%#", callAddress];
cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
cell.detailTextLabel.text = [NSString stringWithFormat:#"%#", callType];
cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
return cell;
}
Now the Delegate Method
#pragma mark -
#pragma mark Table View Delegate Methods*
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSLog(#"%i", row);
CallMapViewController *mapVC = [[CallMapViewController alloc] initWithNibName:#"CallMapViewController" bundle:[NSBundle mainBundle]];
mapVC.annotCallType = callType;
mapVC.annotCallAddress = callAddress;
NSLog(#"%#", mapVC.annotCallType);
NSLog(#"%#", mapVC.annotCallAddress);
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *lat = [f numberFromString:combinedLatString];
NSNumber *lon = [f numberFromString:combinedLonString];
mapVC.annotLatCoord = lat;
mapVC.annotLonCoord = lon;
NSLog(#"%#", lat);
NSLog(#"%#", lon);
NSLog(#"%#", callType);
NSLog(#"%#", callAddress);
[self presentModalViewController:mapVC animated:YES];
}
You already have your tweet data stored in your viewController's property results, so you just need to grab the data from there and parse it again (as Daryl Teo mentions) in didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* tweetText = [[self.results objectAtIndex:indexPath.row] objectForKey:#"text"];
if ([tweetText rangeOfString:#" *** "].location != NSNotFound) {
NSArray *textItems = [tweetText componentsSeparatedByString:#" *** "];
CallMapViewController *mapVC = [[CallMapViewController alloc] initWithNibName:#"CallMapViewController" bundle:[NSBundle mainBundle]];
mapVC.callAddress = [[textItems objectAtIndex:0] stringByReplacingOccurrencesOfString:#" , " withString:#", "];
mapVC.callType = [textItems objectAtIndex:1];
[self presentModalViewController:mapVC animated:YES];
}
}
You get [indexPath row] but you don't use it.
And you've got "callType" and "callAddress" which aren't within the scope of the delegate method. They exist as instance variables of the viewController, and you set their values as you're creating the cells. That's why their values are always the values of the last cell.
You need to store the data in memory, so that you can reference it when you get the row from indexPath.
NSInteger row = [indexPath row];
NSString *tweetText = [tweetsStorageArray objectAtIndex: row];
/* Parse Tweet Text again */
You can either store tweets as text, or create a storage class and store that.
From what I can see in the method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
You take the [indexPath row]; but you don't chose your data base on that.
I see that in your delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath () you are only accessing the selected row variable for NSLog messages.
You would probably need to access the cell using UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath] and its contents using callType = cell.detailTextLabel.text;and callAddress = cell.textLabel.text;

Resources