Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 11, 2012, 05:33 AM   #1
Albright
macrumors member
 
Join Date: Aug 2011
n00b UITableView problem - unexpected scroll behavior

As the title implies, I'm very much a newbie, and this is the first iOS project I've worked on without exactly following the instructions of my Hillegass book. Unfortunately, I'm stumped on something pretty early on. The gist of the app I'm trying to build is that you can enter a search term, and the app will query the English Wikipedia's API for the titles of that same article on other languages' versions of Wikipedia - so it's basically abusing Wikipedia to use it as a multi-lingual dictionary. I've implemented this as a full-screen UITableView which has a single section with a text field in its header where you enter the search term. The results are fetched and put into the table as table cells.

The problem is that when you enter a term which causes the table to fill with more rows than can be shown on screen ("apple" is one I use often for testing since it has about a zillion results (the fruit, not the company)), the table does not scroll correctly; it doesn't move on a one-on-one ratio with my finger movement, and the scroll bar doesn't appear. And when I let go, it scrolls back to the top position - so basically it's reacting as if the table didn't have enough rows to fill the screen.

I think the problem might be that I'm not allocating the window size to the correct bounds, or perhaps that I need to reallocate its bounds after the table is populated, but in either case I'm not sure what the correct behavior should be.

I've attached my project files, if you can be so kind to take a look. Also, if you have a Stack Overflow account and want some points, you can also answer my same question over there (I posted it a few days ago and haven't got an answer yet). Thanks in advance.
Attached Files
File Type: zip WikipediaTrans.zip (40.3 KB, 11 views)
Albright is offline   0 Reply With Quote
Old Nov 11, 2012, 10:18 AM   #2
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
I haven't looked at your project.

Size of window and bounds of table view are not related to this.

I assume that you are dynamically adding rows to the table. How are you doing this? All at once? One at a time? Do you insert new rows or call reloadData? What is your data model?
PhoneyDeveloper is offline   0 Reply With Quote
Old Nov 11, 2012, 05:23 PM   #3
Albright
Thread Starter
macrumors member
 
Join Date: Aug 2011
Quote:
Originally Posted by PhoneyDeveloper View Post
I assume that you are dynamically adding rows to the table. How are you doing this? All at once? One at a time? Do you insert new rows or call reloadData? What is your data model?
I have a data store class (I think that's the right terminology) that basically holds an array of results. After fetching JSON-formatted data from the tubes, my code is parsing it and populating that array with the data, then calling reloadData on the table after that. My cellForRowAtIndexPath implementation gets that array from the data store and formats a cell for the respective result (using the dequeue stuff, which I must confess I don't entirely understand yet). All of the rows appear in the table as expected, so that's working fine; it's just the scrolling behavior of the table after the rows are added that's puzzling me.
Albright is offline   0 Reply With Quote
Old Nov 11, 2012, 11:35 PM   #4
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Use a navigation controller as your rootViewController. You can hide the navigation bar if you like. I think that will fix things.

Alternatively, in didFinishLaunchingWithOptions: don't create the window as the same size as the tableview bounds. Create the window as the same size as the mainScreen bounds. You might want to make a new project and look at how the window is created.

Anyway. I did both those things to your code. The navigation controller fixed the problem, although I'm not exactly sure if there's a way to make the TableViewController act correctly without the nav controller.


Code:
{
  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  // Override point for customization after application launch.
  
  WordsViewController *viewController = [[WordsViewController alloc] init];
  UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  [[self window] setRootViewController:navController];

  self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
PhoneyDeveloper is offline   0 Reply With Quote
Old Nov 12, 2012, 03:58 PM   #5
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by PhoneyDeveloper View Post
...although I'm not exactly sure if there's a way to make the TableViewController act correctly without the nav controller.
I tried setting the rootViewController to a WordsViewController, added a call to startSearch:@"apple" in the viewDidLoad (for now), and commented out the viewForHeaderInSection: method and the scrolling worked as expected. If you uncomment it, the scrolling is incorrect again. It definitely seems to be some strange interaction between the tableView and the headerView that is messing up the scrolling.
dejo is offline   0 Reply With Quote
Old Nov 12, 2012, 06:09 PM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Albright, there is definitely something weird with your WordsHeaderView.xib. I replaced NIB-loading it with some quick-and-dirty code to (mostly) recreate it (as well as removing the __weak directive on the ivar declaration) and I got the scrolling to work as expected. I can't (so far) nail down why that XIB is funky though. Here's my replaced code:
Code:
- (UIView *)headerView {
  if (!wordsHeaderView) {
//    [[NSBundle mainBundle] loadNibNamed:@"WordsHeaderView" owner:self options:nil];
	  wordsHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
	  wordsHeaderView.backgroundColor = [UIColor orangeColor];
	  searchField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
	  searchField.borderStyle = UITextBorderStyleRoundedRect;
	  [searchField addTarget:self action:@selector(searchFieldSearch:) forControlEvents:UIControlEventEditingDidEnd];
	  searchField.delegate = self;
	  [wordsHeaderView addSubview:searchField];
  }
  return wordsHeaderView;
}
EDIT:
I would try recreating your WordsHeaderView.xib piece-by-piece with testing after each change and seeing if you can isolate the one change that causes things to go awry.

P.S. Why did you add the __weak to the searchField ivar?

Last edited by dejo; Nov 13, 2012 at 10:08 AM. Reason: Added more advice.
dejo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:50 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC