UITableView change style - objective-c

I have a uitableView with different sections and rows that I created them programmatically
when I cleck on one row I will go to the new views and in new views in navigation bar I have canel button
with cancel button it should work like a back button but when I click on cancel it load the table but change the table style from group to plain
Thanks in Advance!
does any one know why?
would you please help me
I want to know why it changes.
what should I add to have the same stype
here is my code:
in first table, I added the style both programmatically and via storyboard
- (id)initWithStyle:(UITableViewStyle)style
{
style = UITableViewStyleGrouped;
self = [super init];
if (self) {
self = [super initWithStyle:style];
monthTitle = [[NSMutableArray alloc] init];
}
return self;
}
button code
-(void)cancelItem{
Report *report = [[Report alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:report animated:YES];
[self.tableView reloadData];
}
Edit
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedIndex = indexPath.section;
[self.tableView reloadData];
switch (indexPath.section){
case 0:
[self performSegueWithIdentifier:#"WorkTime" sender:self];

We can set the style as
[[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];

Related

MGSplitViewController as Modal not working correctly

I am trying to use an MGSplitViewController, but rather than having it set as the rootViewController, I want it to show modally. This is the code I am using so far
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath: (NSIndexPath *)indexPath
{
if(splitViewController == nil)
{
self.splitViewController = [[MGSplitViewController alloc] init];
self.rootViewController = [[RootViewController alloc] init];
self.detailViewController = [[DetailViewController alloc] init];
}
[splitViewController setViewControllers:[NSArray arrayWithObjects:rootViewController, detailViewController, nil]];
if (NO) { // whether to allow dragging the divider to move the split.
splitViewController.splitWidth = 15.0; // make it wide enough to actually drag!
splitViewController.allowsDraggingDivider = YES;
}
splitViewController.delegate = detailViewController;
[rootViewController performSelector:#selector(selectFirstRow) withObject:nil afterDelay:0];
[detailViewController performSelector:#selector(configureView) withObject:nil afterDelay:0];
[self presentViewController:splitViewController animated:YES completion:nil];
}
This works almost fine, but the buttons in the detailViewController do not work. They do nothing. Also, when I click a button in the left panel, the text doesn't change in the detailViewController as it does in the same project.
Am I missing something?
I'm also working with MGSplitViewController, but it sounds to me like you need to set up some communication between your master and detail views. If you look at the demo project, you can see they use delegates to that effect.

opening the detail view in searchdisplaycontroller

- (void)viewDidLoad {
[super viewDidLoad];
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 160, 44)];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
self.tableView.tableHeaderView = searchBar;
[searchDisplayController setSearchResultsDataSource: self];
[searchDisplayController setSearchResultsDelegate: self];![enter image description here][2]
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
// inizializziamo l'oggetto Data
_objects = [[Data alloc] init];
filteredlist=[[NSMutableArray alloc]initWithArray:_objects.lista ];
}
In this method I added so as to open the detail view
[searchDisplayController setSearchResultsDataSource: self];
[searchDisplayController setSearchResultsDelegate: self];
The only problem is that it opens the view for that cell, I instead need to open the detail view associated with that name in the list initially loaded.
The problem is to open the corresponding detail view when I do a search
When I do a search I have to open the detail view when I click on the name.
I'm not 100% sure what's you problem here but make sure that in your delegate selectors you check for the tableView parameter to distinguish your search result table view from your initial table view. E.g.:
[...]
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
// ...do your tableView stuff
} else if (tableView == searchDisplayController.searchResultsTableView) {
id someSearchResultObject = [_filteredlist objectAtIndex:indexPath.row];
SomeDetailViewController *vc = [[SomeDetailViewController alloc] initWithSearchResult:someSearchResultObject];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
}
}
[...]
I will just update Tom's answer:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
// ...do your tableView stuff
} else if (tableView == searchDisplayController.searchResultsTableView) {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"detailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
}

not able to click the search bar tableview cell

I've got a tableview containing array of names. The search bar works perfectly filtering the names in the table view.
The problem is the didSelectRowAtIndexpath is not getting fired when clicking the search tableview cell. Could you help me out?
What is the thing that I'm missing? Should I include any special delegate to involve search tableview cell click.
Below is the image and code.
-(void)search
{
nameArray = [[NSMutableArray alloc] init];
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 160, 44)];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
self.tableViewFriendsList.tableHeaderView = searchBar;
}
- (void)searchDisplayController:(UISearchDisplayController *)controller
willShowSearchResultsTableView:(UITableView *)tableView
{
[tableView setRowHeight:70];
[tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.tableViewFriendsList) {
NSString *friendsID =[[[self.friendsDictionary objectForKey:#"data"] objectAtIndex:indexPath.row] objectForKey:#"id"];
[[FacebookHelper sharedFacebookHelper] postOnWallWithDelegate:self andID:friendsID];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSLog(#"I ve come here");
NSString *friendsID =[friendsListIdArray objectAtIndex:indexPath.row];
[[FacebookHelper sharedFacebookHelper] postOnWallWithDelegate:self andID:friendsID];
}
}
You forgot to set
searchController.searchResultsDelegate = self;
I do something in one of my projects that may be of assistance:
// add gesture to detect when table view is being tapped so that keyboard may be dismissed
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(dismissKeyboard)];
gestureRecognizer.cancelsTouchesInView = NO;
[self.tableView addGestureRecognizer:gestureRecognizer];
Moreover I am wondering why you have a search bar within a table cell. Would you mind posting a screen shot of it in your app? I am afraid you may be doing more work than is necessary.

Tablecell click short delay

When I click on table cell, there's a short delay of 1-2 second before it loads the next view. I've seen some apps that show an activity indicator during that time and that's what I'd like to do. I've added one like this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
spinner.frame = CGRectMake(200,200,200,200);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = spinner;
[spinner startAnimating];
[spinner release];
VenueViewController *vviewcontroller = [[VenueViewController alloc] initWithNibName:#"VenueViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:vviewcontroller animated:YES];
[vviewcontroller release];
vviewcontroller = nil;}
however this also appears with a delay, and just before the next view is showing. It seems the app freezes for 1-2 seconds after clicking on the table cell so it doesn't even show the activity indicator.
I think the secret is that you should call load method using a performSelector method. Another tip is hiding or showing the activity so it won't consume time this operation.
So this could be a pseudocode of that
Inside your ViewController class definition:
IBOutlet UIActivityIndicatorView *spin; // created in view and hidden
In your implementation...
-(void) load{ // your code
VenueViewController *vviewcontroller = [[VenueViewController alloc] initWithNibName:#"VenueViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:vviewcontroller animated:YES];
[vviewcontroller release];
vviewcontroller = nil;
spin.hidden=YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
spinner.hidden=NO;
[self performSelector:#selector(load) withObject:nil afterDelay:0];
}
Hope it helps.

Unable to trigger UITableView Delegate Method "DidSelectRowAtIndexPath"

Hi I am using a searchDisplayController to filter through my search results. My code snippet is as follows:
- (void)viewDidLoad
{
[super viewDidLoad];
//Set up search bar
UISearchBar *tempBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,40)];
self.sBar = tempBar;
[tempBar release];
self.sBar.delegate = self;
self.sBar.tintColor = [UIColor colorWithHexString:#"#b6c0c7"];
self.sBar.placeholder = #"Search Questions and Topics";
[self.view addSubview:sBar];
self.filteredListContent = [NSMutableArray arrayWithCapacity:[self.listContent count]];
self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:sBar contentsController:self];
[self setSearchDisplayController:searchDisplayController];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];
// restore search settings if they were saved in didReceiveMemoryWarning.
if (self.savedSearchTerm)
{
[self.searchDisplayController setActive:self.searchWasActive];
[self.searchDisplayController.searchBar setText:savedSearchTerm];
self.savedSearchTerm = nil;
}
[self.resultTableView reloadData];
self.resultTableView.scrollEnabled = YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"zzz");
}
Do I need to setup anything in my view did load to trigger the uitable delegate method?
Note that I have already declared UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate in my .h files. Also my tableView cellForRowAtIndexPath method is working.
Have you actually set
self.tableView.delegate = self
or connected it up in Interface Builder