PDA

View Full Version : [iPhone SDK] UITableView - setEditable Tutorial




zcarter
Mar 22, 2008, 08:36 PM
Hey guys,

I have just uploaded a UITableView - setEditable Tutorial for the iPhone SDK.
You can view it at the link below. This shows you how to get your rows in editing view to be able to delete them. It also shows you how to add/remove buttons in the upper right hand corner of the navigation view.

Let me know what you think!

- Zac

http://www.iphonedevcentral.org/iphonetutorials/UITableView/TableviewsetEditing.zip



lucasgladding
Mar 22, 2008, 10:55 PM
Not sure if you have seen this yet, but you may want to check out the following function.

UIViewController
- (UIButton *)editButton


There are other reasons to configure the button manually for the tutorial, but the editButton method is definitely worth mentioning. My apologies if this is discussed in the tutorial - I haven't had a chance to watch it in full yet.

Thanks for your hard work so far with the site.

zcarter
Mar 22, 2008, 11:09 PM
Wow,

Haha, Still learning all the cool features I guess.

Thanks for the heads up!

Hey, would you be interested in making some home-made tutorials for that site?

Email me at tutorials@iphonedevcentral.org

Seems like you know what you're talking about..

Buschmaster
Mar 22, 2008, 11:13 PM
Thanks for the helpful tutorials!

Perhaps I'll write some VERY beginner ones, I feel like I can struggle through the better stuff right now, but very beginner can be a good thing for when you're just learning.

zcarter
Mar 22, 2008, 11:46 PM
No problem man! This is why Im making iphonedevcentral.org to begin with. So everyone can share all their tutorials and I can just make this huge database of them. I will be posting tutorials of written and video tutorials so if you wanna submit your own, please send them to tutorials@iphonedevcentral.org

Also,

Any requests for tutorials?

- Zac

elbirth
Mar 23, 2008, 02:40 PM
I've checked out this one and the other tutorial you did for the hello world app, and I have to say they're nice resources for helping to understand some stuff.

Maybe you'll do this on your site, but do you know if there are any current sites or other resources available that do video tutorials for actually teaching you programming in Xcode from the start? (not specifically for the iPhone). My only programming experience was a course I took in college for Java, but the professor was horrible, and the TAs didn't want to actually provide help other than telling you to go read the course material, so I ended up dropping it and didn't get much out of it.

It helps me to have someone actually explaining what's going on instead of trying to find a book to read, but I haven't seen any good tutorials that are truly for beginners and doesn't assume you have any programming knowledge.

zcarter
Mar 23, 2008, 04:23 PM
We will have beginners videos explaining what Object Oriented programming is, and how it works. We will start from the very beginning. This is a variable, etc, this is a for loop, this is a while loop, etc. etc.

Hopefully it can get some people started. If you know anything and would like to contribute let me know.


- Zac

Manty
Mar 23, 2008, 04:28 PM
Thanks for the tutorial, i've seen the 3 and it's helping me to get some basic knowledge until june. It's not my first time learning a new language but i have to say that video tutorials help a lot.
So, i can't help with the objective C yet but if you need any help with the site or something, and maybe making video tutorials of the text ones (sry to repeat myself but i rly think its easier).

Looking forward for the next tutorial,
Manty

Monkaaay
Mar 23, 2008, 04:41 PM
Great stuff. I hope you're able to track the downloads of your tutorials! :)

Buschmaster
Mar 24, 2008, 11:45 AM
No problem man! This is why Im making iphonedevcentral.org to begin with. So everyone can share all their tutorials and I can just make this huge database of them. I will be posting tutorials of written and video tutorials so if you wanna submit your own, please send them to tutorials@iphonedevcentral.org

Also,

Any requests for tutorials?

- Zac
As far as requests, it would be nice to see (on top of the hello world one) one on each of the basic ways to handle graphics. CG, UIKit, etc. That way you can get your feet wet with each of those types.

SqueegyX
Mar 24, 2008, 02:08 PM
Very nice! Thanks for this. This and the Hello World you did are really helping me get this down.

I have a question regarding code consistency and conventions. I am new to objective-C but most code I see has method names that start with lower case, and are camelCased with no underscores. In your tutorials I have seen camelcased methods, camel cased that start with a capital letter, and lowercase underscored method names. Are there common conventions for that or is it just your preference? I realize the compiler doesn't care, but most languages have a "Best Practice" around these matters.

Also, I managed to get the delete button to actually work. It took some digging thorugh the docs to figure out how what methods get called when a cell is confirmed to be deleted, but the method you mention at the end is only half the story. You need the delegate method:

- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

Which gets called on the master view when the delete button is hit. I added a 3 line method to MasterView and it deletes items like a charm!

- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
[appController.masterList removeObjectAtIndex:[indexPath indexAtPosition:1]];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
[self buttonPushed];
}

The first line of the method removes the item from the array that feeds the table. So you update your data source BEFORE you update your view. The NSIndexPath class can keep track of your position in nested table views and table view sections. [indexPath indexAtPosition:1] returns the index, as an int, of the table cell that had its delete button tapped.

The next line updates the table view. It expects an array of NSIndexPath objects, but we only have 1, so we make a little array of NSIndexPath objects right inline. This removes the table row from the view, and animates it all pretty.

The last line resets our button. After each deletion the table view automatically exits edit mode. So without this last line, you would still have a blue "Done" button. So after the deletion, you have to simulate hitting the "Done" button by calling the method that handles tapping that button.

Just figured some people might like to know how to tackle that piece of it, before the next video.

Keep it up, man. you rock.

lucasgladding
Mar 24, 2008, 04:06 PM
There is an excellent guide on cocoadevcentral that may be worth checking out. It is pretty old, but will give you the general idea. See:

http://cocoadevcentral.com/articles/000082.php

Regarding removing rows from a table view, make sure you read the release notes in the SDK documentation. Exiting edit mode on removal is a know bug. I don't think the delegate method will be required in the final release. I would think the data source is really meant for the manipulation of the collection.

BTW: cocoadevcentral is an excellent resource for anyone new to Objective-C.

Duke Leto
Apr 13, 2008, 06:54 PM
In addition to the post above with the three line- method.. I devised a way to make a new array without that line... there is probably a method to do this but I did it oldskool lol.


NSMutableArray *tempList = [[NSMutableArray alloc] init];
for(int i=0; i<[indexPath indexAtPosition:1]; i++) {
[tempList addObject:[appController.masterList objectAtIndex:i]];
}
for(int j=[indexPath indexAtPosition:1]+1; j<[appController.masterList count]; j++) {
[tempList addObject:[appController.masterList objectAtIndex:j]];
}


This just makes an array, then puts in the info you need from the other Array. I thought I should put this out to help, especially since everyone around here has been kind in putting up with me.

MacBuddySupport
Jul 17, 2008, 04:38 PM
Ok I have got everything their needs to be for a UITableView. Could some one please tell me how to populate the Table view from the interface and not from code. in other words could some one please help me populate the table view? I have tried this method

contentArray [[NSContentArraywithManagedObjects:@"One", @"Two", nill]
retain];
This way does not seem to work. Actualy, any way with an Array doesn't work.

Please help me.

Also could some one please tell me the line of code that saves the Applications state on the Exit?

Thanks...
:confused: :confused: :confused: :confused: :confused: