- (void) tabBarController: (UITabBarController *) tabBarController didSelectViewController: (UIViewController *) viewController
{
/ / Here is a TableView object
myTable
TablesForCollectionViewController * myTable = [[[TablesForCollectionViewController alloc] initWithNibName: @ "TablesForCollectionView" bundle: nil] autorelease];
myTable = [[[TablesForCollectionViewController alloc] initWithStyle: UITableViewStylePlain] autorelease];
myTable.view.frame = CGRectMake (0, 44, 320, 480);
/ / Initialize scrollView object
UIScrollView * scrollView = [[[UIScrollView alloc] initWithFrame: CGRectMake (0, 44, 320, 440)] autorelease];
scrollView.directionalLockEnabled = YES;
scrollView.pagingEnabled = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.delegate = self;
/ / Initialize the object
collectionViewCollectionViewController * collectionView = [[CollectionViewController alloc] initWithNibName: @ "CollectionView" bundle: nil];
/ / Collection.view contains ScrollView, ScrollView is included in the view
myTableif ([_tabBarController selectedIndex] == 2) {
NSLog (@ "CollectionView");
[MyTable.tableView reloadData]; / / reload the data
TableView[CollectionView.view addSubview: scrollView];
[ScrollView addSubview: myTable.view];
}
}
Brother novice, do not know why reloadData does not work, because by the time I was in this Item, did not update the data. Only after restarting the program to see the updated data. Please heroes pointing 12. Thank you!
Reply:
Was going to say I should didselect reload, you can look surprised, each item will alloc a bunch of points and then add up. . .
This time viewcontroller already on the interface, and direct judgment viewcontroller is not what you need to refresh the controller
tabbarcontroller directly with the parameters, and does not require a variable _tabbabrcontroller the
Also, this time table not add to the interface, basically reloadtable only updates cellinvisible the cell, but of course datasource has been updated, it should also be updated.
Reply:
I have the above code, each point of the third Item, will perform NSLog (@ "CollectionView");, but I just do not know how to refresh, my idea is that as long as I am every point of this item, then I re-initialize the iten corresponding view in the view so that, for example scrollView, TableView, etc., but still no effect. I did not use _tabbabrcontroller but directly on the function of the parameter, does not work!
Reply:
You're right, just for a moment I print data in the database, my data is updated, but it is TableView did not read data updates, that is, did not follow the update! I do not know how to do the ~ ask, thank you
Reply:
If the table only here alloc
I have not noticed a delegate and set up table where datasource
I wonder if this will not be caused.
Reply:
I was set in viewDidLoad in
self.tableView.delegate = self;
self.tableView.datasource = self;
Later, I tried to call viewWillAppear: [self.tableView reloadData];
Then
if ([_tabBarController selectedIndex] == 2) {
NSLog (@ "CollectionView");
TablesForCollectionViewController * myTable = [[[TablesForCollectionViewController alloc] init] autorelease];
[MyTable viewWillAppear: YES];
}
So or not, it seems reloadData failure, failure in the Internet to find some reason, and I can not the same. On the card in which the ~
Reply:
This time did not see it, I do not know
However, I always felt, should not be new stuff
didselectLike five drawers, should be the first one to fill in a switch, rather than switching when filling stuff.
If you speak from a design perspective
Because tabbar just one item in the container, but item is viewcontroller things
At this point it should just tell viewcontroller, your item is selected,
After receipt of the corresponding viewcontroller selected messages do their thing (updated)
tabbar ultra vires, perhaps after the code will become ugly.
A little humble.
Reply:
You're right, thank you! I am also a last resort, to see such works can only do so.
I think so, I think it possible, when you press the other item, put the item in the Controller to the first launch of the stack, and then re-initialized by the time this item inside the view, push should be automatic, right? Do not know whether this is feasible, I can not figure out a solution ~
Reply:
I believe the same code and apple, there must be an elegant solution.
What ideas have to try it, definitely rewarding.
Reply:
Your tabBar initialization Items should be initialized each controller. In didselect method you only need to view the display will be launched out on it.
Reply:
reloadData should not call at this location
Reply:
I solved the problem I reorganized my code I use the item on the view controller with inherited UItableViewController, rather than UIViewController then no further rewriting
- (Void) tabBarController: (UITabBarController *) tabBarController didSelectViewController: (UIViewController *) viewController
This function, but to [self.table reloadData] directly in the tableView's ViewWillAppear, and then re-read the contents of the database, on the line. I might say a bit chaotic, thank you for your answer ~
Reply:
Chaos, I do understand that the method is very LO.
O (∩ _ ∩) O
Reply:
You tableview in didSelect method where you need to update the controller in the tableview do? ....
And your tableview how alloc in twice? Do not understand ...
Reply:
You should not be in didselect alloc new control method in adding to the controller, you should define these controls in the controller, and then use the proxy method to determine this tabbarcontroller enter in which controller, for example, you go into the third, you can determine, this is the case, then it is
[Controller.tableview reloadData]; proxy method is not an argument it should make good use ah
No comments:
Post a Comment