Removing NSLog breaks compiler - iphone

Okay, so this is weird
I have this code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 1:
NSLog(#"Platform Cell Selected");
AddGamePlatformSelectionViewController *platformVC =
[[AddGamePlatformSelectionViewController alloc]
initWithNibName:#"AddGamePlatformSelectionViewController" bundle:nil];
platformVC.context = context;
platformVC.game = newGame;
[self.navigationController pushViewController:platformVC animated:YES];
[platformVC release];
break;
default:
break;
}
}
Which works fine.
When I remove the NSLog Statement, like so:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 1:
//NSLog(#"Platform Cell Selected");
AddGamePlatformSelectionViewController *platformVC =
[[AddGamePlatformSelectionViewController alloc]
initWithNibName:#"AddGamePlatformSelectionViewController" bundle:nil];
platformVC.context = context;
platformVC.game = newGame;
[self.navigationController pushViewController:platformVC animated:YES];
[platformVC release];
break;
default:
break;
}
}
I get the following compiler errors
/Users/DVG/Development/iPhone/Backlog/Classes/AddGameTableViewController.m:102:0 /Users/DVG/Development/iPhone/Backlog/Classes/AddGameTableViewController.m:102: error: expected expression before 'AddGamePlatformSelectionViewController'
/Users/DVG/Development/iPhone/Backlog/Classes/AddGameTableViewController.m:103:0 /Users/DVG/Development/iPhone/Backlog/Classes/AddGameTableViewController.m:103: error: 'platformVC' undeclared (first use in this function)
If I just edit out the two // for commenting out that line, everything works swimingly.

You can't declare an object (e.g. AddGamePlatformSelectionViewController *platformVC) as the first line in case...
You can solve it by adding some code before than (e.g. NSLog) or by enclosing the code inside the case between { ... } like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 1:
{
AddGamePlatformSelectionViewController *platformVC = [[AddGamePlatformSelectionViewController alloc]
initWithNibName:#"AddGamePlatformSelectionViewController" bundle:nil];
// the rest of the code...
break;
}
}
}

Do you get the same error if you delete the NSLog statement instead of commenting it out? Maybe the compiler just doesn't like that you're starting a case block with a comment. (Ridiculous, I know, but worth a shot?)

Related

load uiviewcontroller after click on uitableviewcell iOS

I'm little confused of how to implement simple uitableview based menu.Something like in Kayak app http://www.sendspace.com/file/igv31p
My storyboard look like this: navigation controller --->master view controller --> detail view controller. In master view controller i've got a table view. I populated it dynamically with 4 cells which are Products, Stores, Packages and Finances. All I want to do is to display child uiviewcontroller that will be a child uiviewcontroller. Something like this:
Products --> UiViewController with specific functionality
Stores --> Other UIViewControlelr with specific functionality
... and so on.
I create didselectrowatindex method
and try to do something with pushViewController like in code below method but it doesn't work.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
StoresViewController *storeView = [[StoresViewController alloc]init];
switch (indexPath.section) {
case 0:
switch (indexPath.row) {
case 0:
{
NSLog(#"Products");
}
break;
case 1:{
[self.navigationController pushViewController:storeView animated:YES];
NSLog(#"Stores");
}
break;
case 2:{
NSLog(#"Packages");
}
break;
case 3:{
NSLog(#"Finances");
}
break;
}
break;
default:
break;
}
I would appreciate if someone can help me to understand it. If this question was asked before please show me where:) Thanks in advance
Something like in Kayak app
http://www.sendspace.com/file/igv31p
Just replace this code..
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.section) {
case 0:
switch (indexPath.row) {
case 0:
{
NSLog(#"Products");
}
break;
case 1:
{
UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:#"StoresViewController"];
[self presentViewController:navigationController animated:YES completion:nil];
NSLog(#"Stores");
}
break;
case 2:
{
NSLog(#"Packages");
}
break;
case 3:
{
NSLog(#"Finances");
break;
}
break;
default:
break;
}
}
StoresViewController *storeView = [[StoresViewController alloc]initWithNibName:#"StoresViewController" bundle:nil];
simply passed the nib when you create the objcet.

Removing the tableHeaderView from UITableView

This is kind of weird! When I run the app on simulator it works fine but on the device it does not remove the tableHeaderView. Here is my code:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(UITableViewCellEditingStyleDelete == editingStyle)
{
BOOL success = [Service deleteNoteByNoteId:note];
if(success)
{
[self updateTableViewHeader];
}
}
}
-(void) updateTableViewHeader
{
if([self.selectedVegetableGarden.notes count] > 0)
{
self.tableView.tableHeaderView = [self createSharingView];
}
else
{
self.tableView.tableHeaderView = nil;
}
}
The line self.tableView.tableHeaderView = nil gets triggered but it never removes the table header.
I don't think that is the right way to do it. You're nilifying a view that your table view is managing. Why don't you try instead returning either your custom view or nil form UITableViewDelegate's method - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section. I believe that's the right way to do it. You can ask the OS to call that method by executing the following line:
[self.tableView reloadData];
Hope this helps!

iPhone: remove section in TableView

I'm working with table view and sections...In some case I need do remove one section, in another set it back. I can do that in 2 ways:
1)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (somecase) {
return 2;
} else {
return 3;
}
}
and than
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *tableViewCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
[tableViewCell autorelease];
tableViewCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (sectionNumber == 3 {
switch (indexPath.section) {
case 0:
break;
case 1:
break;
case 2:
break;
}
} else if (sectionNumber == 2) {
switch (indexPath.section) {
case 0:
break;
case 1:
break;
}
return tableViewCell;
}
}
And a second way is to implement
[self.tableView beginUpdates];
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:NO];
[self.tableView endUpdates];
But it's not working...I put this methods to ViewDidLoad, is that ok ? Or I should put in somewhere else ? Or what is the problem ?
And what is the best practice for removing section ? first one or second ? thanks....
set condition that will satisfy "somecase " then reload tableview
[tableview reloadData];

selecting row at indexpath doesn;t work

Hi guys i have different section in my tableview ( more than 6) and each one has different rows. But only one of them leads to next view controllers
here is the code but when i click it its not working
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
switch (section)
{
case 5:
{
switch (row)
{
case 0:
{
Language_view_controller * language_controller = [Language_view_controller alloc];
[self.navigationController pushViewController:language_controller animated:YES];
[language_controller release];
}
break;
default:
break;
}
}
break;
default:
break;
}
}
You are just allocating the memory for your view controller, you also need to initialize it by doing something like this:
Language_view_controller * language_controller = [[Language_view_controller alloc] initWithNibName:#"Language_view_controller" bundle:nil];
[self.navigationController pushViewController:language_controller animated:YES];
[language_controller release];

UITableView issues

Iam adding objects to NSMutableArray and displaying the value in UITableView. Only the first object of the NSMutableArray is getting displayed.Where am i going wrong?
My Code snippet:
-(IBAction) segmentedControlIndexChanged:(id)sender {
int selectedSegment = ((UISegmentedControl*) sender).selectedSegmentIndex;
switch (selectedSegment) {
case 1: {
MatchSchedule *semiFinal1 = [[MatchSchedule alloc] initWithDeails:#"20 March"];
MatchSchedule *semiFinal2 = [[MatchSchedule alloc] initWithDeails:#"24 March"];
matchList = [[NSMutableArray alloc] initWithObjects:semiFinal1,semiFinal2,nil];
[semiFinal1 release];
[semiFinal2 release];
break;
}
default;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
....
MatchSchedule *matchSchedule = [knockoutStage objectAtIndex:indexPath.row];
cell.textLabel.text = matchSchedule.matchDate;
}
Hard to tell without seeing more of your code. Are you returning the correct value for
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [knockoutStage count];
}
?