Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

indexPath.row in BlogReader app not showing up correctly.

Hi Guys I have a problem here. The Blog Reader app uptill now is showing up correctly as what is being taught by Amit. My problem is in the following video the indexPath.row (i.e the row number of the row selected in the app) is not showing up correctly in the console in the following line: NSLog(@"Row Selected :%d",indexPath.row);

The compiler is taking row number 0 as row number 1( that is when i am clicking the top most row it is not responding and when i am selecting the row next to it (i.e the row number 1) it is showing Row Selected :0) It is not recognizing the topmost row and starting from the row after it. Also my topmost row is too much near to the header.

Thanks...

7 Answers

Stone Preston
Stone Preston
42,016 Points

I think I remember Amit Bijlani making a forum post about putting a header view in your tableView to increase the distance from the status bar, but I cant seem to find it. You should be able to drag a UIView into the very top of your tableView in storyboard and size it as needed to provide a spacer between the status bar and your tableView. As for your other problem, can you post the code for your didSelectRowAtIndexPath method

Stone Preston
Stone Preston
42,016 Points

Here is your issue

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Row Selected :%d",indexPath.row);

you implemented didDeselectRow not didSelectRow. Change it to didSelectRowAtIndexPath and see if it works

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

For status bar issue see: https://teamtreehouse.com/forum/the-status-bar-is-in-the-way

As for the other issue, I've seen students implementing the wrong method didDeselectRowAtIndexPath which gives them the behavior you are describing above. You should be implementing didSelectRowAtIndexPath.

Hi Stone Thanks for the prompt reply but still am not able to get by this what u said: You should be able to drag a UIView into the very top of your tableView in storyboard and size it as needed to provide a spacer between the status bar and your tableView. How do it do that....

Regarding the code here it is. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Row Selected :%d",indexPath.row);

}

Also , my simulator does not match what Amit Bijlani is using in the videos.

If I am trying to print the row numbers via indexPath.row in the

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ } method, they are showing up correctly. its only the didSelectRowAtIndexPath the row's are not showing up correctly.

Thanks....

Stone Preston
Stone Preston
42,016 Points

in storyboard go to your view controller. drag a new UIView object from the objects panel on the far right to the very top of your tableView, you should be able to place it in the header section. Then you can change the height of that UIView to increase the distance from thettop.

Ahhhhhaa !!! what an eye you have got.... I must compliment you on that stone..... How could i not notice that!!!!!

Here is the link which Amit had posted... https://teamtreehouse.com/forum/blog-reader-app-table-cells-touching-the-header

It works fine now.... But I am still not able to get what u meant by this: in storyboard go to your view controller. drag a new UIView object from the objects panel on the far right to the very top of your tableView, you should be able to place it in the header section. Then you can change the height of that UIView to increase the distance from thettop.

I tried .....but am not sure if i got it done correctly.....

Stone Preston
Stone Preston
42,016 Points

Amits way accomplishes the same thing but programmatically. What I was explaining (or trying to explain) was a way to do it using the storyboard GUI, not in code. Either way, they do the same thing.

Stone Preston
Stone Preston
42,016 Points

RASHU BHATNAGAR here is a SO Post that has a nice screenshot of what I mean by dragging and dropping a view into the top of the tableView. Notice that they are using an imageView, but you could use anything. A blank UIView was what I was suggesting you use.

Yes Amit I got that... Thank you so much for replying back.....

Hi Stone, Thanks for the link.... I finally got what u meant.... And it does work with the way you were suggesting...

Thanks So much!!!