Ipad TableView for UISplittview - ipad

I have a splittView and on the left side of my splittview I added an UITable.
#interface LeftViewController : UITableViewController
I also added all the functions which are requiered for the my Tableview.
I also can see and put data into my tableview...
Now I was trying to add a background Image or set the first cell as a default cell and I notice that I have nowhere a tableview declared in my code ( except of the tableview functions)
How is that possible and how can I set now a background image or select the first cell?
I know that this is the code to select the cell, but there is no myTableView....
- (void)viewDidAppear:(BOOL)animated {
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
[myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionBottom];
}
Do I have to create a new tableview?
Best regards

Customizations are normally done in the viewDidLoad method. Since you are using a UITableViewController you can access the table view through the tableView property.
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionBottom];

Related

UITableView Delegate

I have a table view cell with a "Show More" button. On clicking the button I want the delegate
-tableView:didSelectRowAtIndexPath: to get called ?
Can someone tell me the difference between the following 2 statements:
[self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
and
[[self.tableView delegate] tableView:self.tableView didSelectRowAtIndexPath:indexPath];
There shouldn't be any difference between those two statements, assuming that self is the delegate of the table view, and you have a property called tableView in your controller that points to the table view (connected to the table view in IB if it's an outlet, or assigned to the table view in code if you created the table view there).

How can I use PFQueryViewController as a subview of UITableViewController?

I’m trying to build a group messaging app with Parse. I would like to use storyboards only because I am new to iOS.
The first screen is a UITableViewController with a list of groups.
The second screen is a PFQueryTableViewController that inherits from UITableViewController with a list of messages for that group.
I would like to add a chat box(UITextField) to the PFQueryViewController, but I can’t seem to do that because it is a UITableViewController.
From what I can tell in order to add a chat box I need to use a UIViewController and manually add a table view. Then resize the table view to allow for a chat box at the bottom.
The problem is then PFQueryViewController inherits from a UITableViewController and not a UITableView.
I am using this to pass the selected group PFObject to the new PFQueryViewController.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
[self performSegueWithIdentifier:#"detail" sender:nil];
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
if([[segue identifier] isEqualToString:#"detail"])
{
NSIndexPath *ip = [self.tableView indexPathForSelectedRow];
PFObject *passObj = [self.objects objectAtIndex:ip.row];
PFQueryTableViewController *messageDetail=[segue destinationViewController];
[messageDetail setReceiveObj:passObj];
messageDetail.hidesBottomBarWhenPushed = YES; //Hide Tab Bar
}
How can I use PFQueryViewController as a subview of UIViewController and pass the PFObject to that controller?
*I don't have enough reputation for images
I'm, unfamiliar with the Parse framework but you should be able to use View Controller Containment to achieve this.
Here is a nice guide to check out.
Here is the relevant part for adding the view of a view controller as a subview in another view controller:
// put this in viewDidLoad
[self addChildViewController:_pfQueryController]; // 1
[self.view addSubview:_pfQueryController.view]; // 2
[_pfQueryController didMoveToParentViewController:self]; // 3

how to call selectItemAtIndexPath immediately

I am using this line
[self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
inside the cellForItemAtIndexPath method, to programatically select an item in the collection view and it is working, the problem is that it only works after I touch the collection view. How do I get it to work immediately after the collection view is loaded?
Call it inside viewDidLoad or viewDidAppear.
If you know the position you want to select on load, you can create a NSIndexPath object by using: [NSIndexPath indexPathForRow:inSection:]
For example: NSIndexPath *myIndex = [NSIndexPath indexPathForRow:0 inSection:0];

deselectRowAtIndexPath issue

I have just started working with tableViews, and I have 5 cells in a tableview in a viewController embedded in a navigationController. When a cell is pressed another view is pushed in. My problem is that the cell I press is selected but the selection doesn't go away. I have tried with this code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NewViewController *newViewController = [[NewViewController alloc] init];
newViewController.theTitle = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;
[self.navigationController pushViewController: newViewController animated:YES];
}
The tableView is initialized in the viewDidLoad method. Still when I click a cell the new viewController is pushed in but the cell stays selected. What might be the issue here?
You've put your code in the didDeselectRowAtIndexPath - put it in the didSelectRowAtIndexPath. This is an easy mistake to make since didDeselect comes up in code completion before didSelect.
Summary :
You have tableview that is in a ViewController that is in a NavigationController
Use touch a cell
A new ViewController is push on the NavigationController Stack
User hit back and goes back to the screen where you have a tableView
That is what I understand from your question.
At this moment the cell in your tableView should still be selected in order for the user to have a reminder of the last action he as done, but you also want it to get unselected animated at the point ( the mail application is a good example of this behaviour).
So the best place to deselect the cell in your tableView is in - (void)viewDidAppear:(BOOL)animated method of the UIViewController that have the tableview inside it's view. By doing so you will let the user a chance to see the selection before it gently fade away like in mail.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:animated];
}
You can pass nil as argument of deselectRowAtIndexPath, tableView handles it gracefully.
Did you also implement tableView:didSelectRowAtIndexPath:? This method is called every time you tap a cell. So you should put your code there.
The method you are using, tableView:didDeselectRowAtIndexPath: is called whenever a cell is selected and you are tapping a different cell.
I think your problem is that you use wrong method. Change didDeselectRowAtIndexPath to didSelectRowAtIndexPath.

Stop activityIndicator in Embedded TableView Cell Upon Return From Detail ViewController

I have a viewController that has a container view. In the container view I have a tableView that contains static cells. Each cell has a disclosure indicator. This was all created in IB. The parent viewController is embedded in a navigationController.
Each cell pushes a new view controller which loads a mapView. Each map parses and loads a .kml file. The .kml files are huge and take up to a minute (or more) to load.
I placed an activityIndicator in the accessory view of each cell using the following code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *activityView =
[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityView startAnimating];
[cell setAccessoryView:activityView];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];}
This appears to work as expected.
After viewing the map I touch the "back" button provided by the navigationController and pop the map off the stack. My embedded tableView is visible again, with the activity indicator still spinning. I can't get it to stop.
My best attempt was in the implementation file of my tableView:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[self tableView] reloadData];}
But that didn't work. Any suggestions?
Calling reloadData in the table view controller's viewWillAppear would work as long as in the cellForRowAtIndexPath method, you're setting the state for UIActivityIndicatorView by calling it's stopAnimating method (or simply remove it from the view) for any cell that shouldn't be spinning.
You'll need to reference the activity indicator via the accesstoryView property.
In your data, you could store a property that indicates whether the indicator should still be spinning for that map and set it appropriately.
Another method would be to stop the activity indicator in prepareForSegue, just prior to showing the map view.

Resources