How to use NSUserDefault to send selected TableViewCell text to previous ViewController - ios

I have a static UITableView with two prototype cells in my first UIViewController. in the first cell there is a label with "select your country". When user tap that cell, it goes to another UITableViewController that includes countries. When user select a country, in the first view label text should update with the selected country name. To do that I have to pass the selected data in second UIViewController to first view controller. I hope to use NSUserDefaults to do that. this is my second view controller with a tableview.
#implementation FlightfromTableViewController
{
NSArray *detailFlights;
}
- (void)viewDidLoad {
[super viewDidLoad];
detailFlights = #[#"colombo1",#"colombo2",#"colombo3",#"colombo14",#"colombo15",#"colombo16",#"colombo17"];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [detailFlights count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"identi" forIndexPath:indexPath];
cell.textLabel.text = [detailFlights objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
Pass *p = [Pass new];
p.selectedString = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
NSString *selecteOne = p.selectedString;
[[NSUserDefaults standardUserDefaults] setObject:selecteOne forKey:#"selectedplace"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
I appreciate if you provide answer with understandable code, because I'm new to iOS.

NSUserDefaults should not be used for application state. It's for user preferences which should persist when the app closes.
The correct way is to pass your data directly between your viewcontrollers: https://stackoverflow.com/a/9736559/78496

As suggested by #chedabob, NSUserDefaults should not be used to maintain application state.
Instead, you can use Protocols to back propagate the selection in First View Controller.
In your case, just use
[[NSUserdefaults standardUserDefaults] objectForKey:#"selectedplace"];
in viewWillAppear of FirstViewController to update the string.

First of all - you don't need to much code in your didSelect method to get your selected string. Just use your array:
NSString *selectedText = [detailFlights objectAtIndex: indexPath.row]; // or detailFlights[indexPath.row]
And when you come back to your master (first) ViewController you need to update your TableView, because data has changed. So, add viewWillAppear (if you haven't one) method and refresh your table:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
[self.tableView reloadData]; // put here name of your tableView's property
}
And then, in your cellForRow method:
...
if (indexPath.row == 0) { // in first row you store country
NSString *text = #"Select country"; // default text
NSString *selectedCountry = [[NSUserdefaults standardUserDefaults] objectForKey:#"selectedplace"];
if (selectedCountry) { // if it exist
text = selectedCountry;
}
cell.textLabel.text = text;
}

You can get value from NSUserDefault by using this code in your First View Controller.
NSString *selectedPlace = [[NSUserdefaults standardUserDefaults] objectForKey:#"selectedplace"];

You should use delegate pattern to inform the first view controller about selected country. For this you have to write protocol in second view controller.
#protocol SecondViewControllerDelegate
-(void)secondViewController:(UIViewController *)vc selectedCountry:(NSString *)country;
#end
then in
(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
delegate.secondViewController(self) selectedCountry:#"selectedCountry";
}
After that in first view controller you implement this menthod to update the value.

Related

didSelectRowAtIndexPath not called on Touch

My didSelectRowAtIndexPath method not called. I reload table and its reloaded and also called all methods of talbeView
Here is my all methods of tableview :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *s = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row];
NSString *cellIdentifire = #"CellRoomList";
CellRoomList *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifire];
if(cell == nil)
{
cell = (CellRoomList*)[[[NSBundle mainBundle] loadNibNamed:#"CellRoomList" owner:self options:nil] objectAtIndex:0];
}
cell.lblRoomName.text = s;
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [app.Glb.arrayRoomList count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *userName = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row];
NSLog(#"userName :---- %#",userName);
ViewController *chatController = [[ViewController alloc] init];
chatController.chatWithUser = userName;
[self.navigationController pushViewController:chatController animated:YES];
}
I read some questions in stack but can't get answers.
and if i long touch to cell than it cell's color change but not called didSelectRowAtIndexPath
Why its not called ?
Here is Snap :
There might be other views in cell that could intercepting the touch events. Make sure to set NO to the property userInteractionEnabled for views.
I had faced this general issue so many times.
Please take care of following things
Make sure your cell dont have any type of touch/tap gestures to its contents
Make sure your view dont have any touch/tap gestures applied
Make sure you dont have any View or Table view categories(extension) that has any touch/tap gestures applied [This is more critical as we don`t expect this usually]
Check if you have any third party who works for touch/tap gestures
The most common reasons are gestures on view that prevent the table to get touches on cell.
As you told you are getting user name, it means your method is calling but not redirecting to another screen, as you have initiate view controller in wrong manner so change it by below,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *userName = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row];
NSLog(#"userName :---- %#",userName);
ViewController *chatController = [[ViewController alloc] initWithNibName:#"ViewControllerId" bundle:nil];
chatController.chatWithUser = userName;
[self.navigationController pushViewController:chatController animated:YES];
}
Check if selection is set to single selection!

Problems when dismissing a modal UIViewController with a UITableView in it

So I have a UIViewController that I'm presenting over the current view modally. This view controller consists only of a UITableView (for selecting items), and a navigation bar at the top which has a Cancel button in case you don't want to select anything.
The whole thing works just fine in almost any situation. Selecting an item works, pressing the cancel button dismisses the view, everything is fine. However, there's one case that causes the app to crash: when you swipe left on an item in the table view to reveal the delete button, then press the cancel button at the top to dismiss the view, the app crashes and it doesn't say anything about the cause of the crash in the console output. Here's the code for the view controller I'm presenting modally:
.h:
#import <UIKit/UIKit.h>
#import "common.h"
#interface LoadViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
- (IBAction)lCancelButton:(id)sender;
#property (weak, nonatomic) IBOutlet UITableView *lTableView;
#end
.m:
#import "LoadViewController.h"
#interface LoadViewController () {
NSMutableArray* sampleCounts;
NSArray* tableData;
}
#end
#implementation LoadViewController
#synthesize lTableView = _lTableView; // This is the table view itself
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Deleting an item when the delete button is pressed
[self.lTableView beginUpdates];
// Deleting it from the table view first
[self.lTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
// ... then from the arrays as well
[sampleCounts removeObjectAtIndex:indexPath.item];
// (making a mutable copy here so I can delete stuff from it)
NSMutableArray* tmp = [tableData mutableCopy];
[tmp removeObjectAtIndex:indexPath.item];
tableData = tmp;
[self.lTableView endUpdates];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.lTableView.allowsMultipleSelectionDuringEditing = NO;
sampleCounts = [NSMutableArray array];
tableData = [NSMutableArray array];
// I'm filling up both arrays with the appropriate data here...
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)lCancelButton:(id)sender {
// Dismiss the view controller when Cancel is pressed
[self dismissViewControllerAnimated:YES completion:nil];
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.tableData.count;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// If an item gets selected, store the name of it (I use a class called 'common' for storing data like this), then dismiss the view
[common setItemName:[tableData objectAtIndex:indexPath.item]];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString* ID = #"ID";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
cell.textLabel.text = [self.tableData objectAtIndex:[indexPath row]];
cell.detailTextLabel.text = [sampleCounts objectAtIndex:[indexPath row]];
return cell;
}
#end
So as you can see, it's very simple. I have the item names and the descriptions of them in two separate arrays (both arrays hold NSString*s), I fill up the table view with that information, and that's it. The rest is pretty straight forward.
So does anyone have any idea why the app crashes when I swipe on an item to reveal the delete button, and then dismiss the view controller by pressing Cancel? In every other case, everything works perfectly fine. It only crashes when I press Cancel whenever a delete button is visible.
Try the following:
- (void)viewWillDisappear:(BOOL)animated
{
self.lTableView.editing = NO;
}
What I can think of is about your mode.
Probably is you are in the editing mode.
So, try to go back to the normal mode before dismissing.
[self.tableView setEditing:No];

iOS: I am trying to send the selected rows(data) to another controller.

I have a tableview for which I am using
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
I have an NSArray *selectedDiscounts which I have assigned like this
selectedDiscounts = [self.tableView indexPathsForSelectedRows];
I have to pass the selected table rows data to another controller where I will be populating the tableView with selected rows.
The problem is selectedDiscounts either holds only selected indexPaths and not the data? because of which it shows me the number of objects that are selected but not the data for those selected cells.
I want to store the selected rows data into an NSArray variable. Is that possible? Thanks guys.
You need to iterate through all of your index paths and get the data yourself.
NSMutableArray *array = [[NSMutableArray alloc] init];
for (NSIndexPath *indexPath in selectedDiscounts) {
// Assuming self.data is an array of your data
[array addObject: self.data[indexPath.row]];
}
Now you have your NSArray that contains your data that can you pass to your next controller.
Your selectedDiscounts array is clearly being populated with the UITableView method indexPathForSelectedRows. To store the actual data for the selected rows you need to first establish an array allDiscounts, with which you populate your first table view. Then, when you are displaying all of the objects from allDiscounts and you want to select some and store the data do this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[selectedDiscounts addObject:[allDiscounts objectAtIndex:indexPath.row]];
}
The way I would handle this, is to create a custom initializer method on the view controller you want to pass the data to. Something like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *selectedDiscounts = yourDataSource[indexPath.row];
NewViewController *newVC = [[NewViewController alloc] initWithSelectedDiscounts:selectedDiscounts];
self.navigationController pushViewController:newVC animated:YES];
}
An alternate method would be create a property on the second view controller that is the array/dictionary you want to pass, and when they select the row, get the information for the row, and set it on the view controller before you push/present it.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *selectedDiscounts = yourDataSource[indexPath.row];
NewViewController *newVC = [[NewViewController alloc] initWith...// whatever you use for the initializer can go here...
newVC.discounts = selectedDiscounts;
self.navigationController pushViewController:newVC animated:YES];
}

Phone Call within Table Cell

Im writing an app where someone adds a contact to the app, giving their name, number and photo. Then this information is displayed in a table, with each individual contact on a different cell and when the user presses on the cell it will call the number that was typed in for the contact. I have put in a large button on each of the cells for the user to press. This is the code
PictureListMainTable.m
#import "PictureListMainTable.h"
#import "PictureListDetail.h"
#import "CoreDataHelper.h"
#import "Pictures.h"
#implementation PictureListMainTable
#synthesize managedObjectContext, pictureListData, callButton;
// When the view reappears, read new data for table
- (void)viewWillAppear:(BOOL)animated
{
// Repopulate the array with new table data
[self readDataForTable];
}
// Grab data for table - this will be used whenever the list appears or reappears after an add/edit
- (void)readDataForTable
{
// Grab the data
pictureListData = [CoreDataHelper getObjectsForEntity:#"Pictures" withSortKey:#"title" andSortAscending:YES andContext:managedObjectContext];
// Force table refresh
[self.tableView reloadData];
}
#pragma mark - Actions
// Button to log out of app (dismiss the modal view!)
- (IBAction)logoutButtonPressed:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
#pragma mark - Segue methods
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get a reference to our detail view
PictureListDetail *pld = (PictureListDetail *)[segue destinationViewController];
// Pass the managed object context to the destination view controller
pld.managedObjectContext = managedObjectContext;
// If we are editing a picture we need to pass some stuff, so check the segue title first
if ([[segue identifier] isEqualToString:#"EditPicture"])
{
// Get the row we selected to view
NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
// Pass the picture object from the table that we want to view
pld.currentPicture = [pictureListData objectAtIndex:selectedIndex];
}
}
#pragma mark - Table view data source
// Return the number of sections in the table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Return the number of rows in the section (the amount of items in our array)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [pictureListData count];
}
// Create / reuse a table cell and configure it for display
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Get the core data object we need to use to populate this table cell
Pictures *currentCell = [pictureListData objectAtIndex:indexPath.row];
// Fill in the cell contents
cell.textLabel.text = [currentCell title];
cell.detailTextLabel.text = [currentCell desc];
int number;
number = [currentCell desc];
-(IBAction)MakePhoneCall:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:",number]];
}
// If a picture exists then use it
if ([currentCell smallPicture])
{
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
cell.imageView.image = [UIImage imageWithData:[currentCell smallPicture]];
}
else{
}
return cell;
}
// Swipe to delete has been used. Remove the table item
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Get a reference to the table item in our data array
Pictures *itemToDelete = [self.pictureListData objectAtIndex:indexPath.row];
// Delete the item in Core Data
[self.managedObjectContext deleteObject:itemToDelete];
// Remove the item from our array
[pictureListData removeObjectAtIndex:indexPath.row];
// Commit the deletion in core data
NSError *error;
if (![self.managedObjectContext save:&error])
NSLog(#"Failed to delete picture item with error: %#", [error domain]);
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
-(IBAction)MakePhoneCall:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:",number]];
}
#end
PictureListMainTable.h
#import <UIKit/UIKit.h>
#interface PictureListMainTable : UITableViewController
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (strong, nonatomic) NSMutableArray *pictureListData;
#property (nonatomic, retain) IBOutlet UIButton *callButton;
-(IBAction)MakePhoneCall:(id)sender;
- (void)readDataForTable;
#end
Where should I place the IBaction and why isint it working at the moment where it is and how can I make it work?
There are a couple of approaches you could take to achieve this. But firstly, I don't understand what you are doing at the bottom of -tableview:cellForRowAtIndexPath:. It's as if you are trying to define your IBAction method inside this method. You also have it defined at the bottom of the implementation, but in that method the number variable is not in scope.
Anyway, you should subclass the UITableViewCell. In the implementation for the subclass, you should define the IBAction method and hook it up in interface builder, or otherwise.
When the button is tapped, you should hand the number for the selected cell back to the PictureListMainTable view controller, in order for that view controller to process it (i.e. call the number). You can do this in two ways:
1) the delegate method
Create a protocol, defined in the header file for your subclass of UITableViewCell. And make the main view controller conform to this protocol. Set the cell's delegate to the main view controller. In the implementation of the cell subclass, call this delegate method. For example:
the header file for the UITableViewCell subclass "PictureListMainTableCell.h"
#protocol PictureListMainTableCellDelegate;
#interface PictureListMainTableCell : UITableViewCell
#property (nonatomic, copy) NSString *telephoneNumber;
#property (nonatomic, weak) id<PictureListMainTableCellDelegate> delegate;
#end
#protocol PictureListMainTableCellDelegate
-(void)pictureListMainTableCell:(PictureListMainTableCell *)cell wantsToCallNumber:(NSString *)number;
#end
the implementation file "PictureListMainTableCell.m"
#import "PictureListMainTableCell.h"
#implementation PictureListMainTableCell
-(IBAction)MakePhoneCall:(id)sender
{
//send the delegate the number to call.
[self.delegate pictureListMainTableCell:self wantsToCallNumber:self.telephoneNumber];
}
#end
Above, in the MakePhoneCall method, we call -pictureListMainTableCell:wantsToCallNumber: on the delegate. In this case, the delegate is your main view controller. We will set this below.
Setting the cell's delegate: In your main view controller file (PictureListMainTable.m), in the -tableView:cellForRowAtIndexPath: method, set the delegate on the cell to self. e.g.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get the cell...
PictureListMainTableCell *cell = // dequeue the cell
// do some other setting up...
// set the delegate on the cell
cell.delegate = self;
// set the telephoneNumber variable on the cell, for example...
cell.telephoneNumber = [currentCell desc];
return cell;
}
Now you need to make sure self implements the delegate method. So still in PictureListMainTable.m, you need to define the method as follows:
#pragma mark - PictureListMainTableCellDelegate methods
-(void)pictureListMainTableCell:(PictureListMainTableCell *)cell wantsToCallNumber:(NSString *)number
{
NSString *urlString = [NSString stringWithFormat:#"tel://%#", number];
NSLog(#"calling telephone number [%#]", number);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
You should also specify that the PictureListMainTable class conforms to your new protocol, as well as the UITableViewDataSource protocol. Add a private category on PictureListMainTable as follows (at the top of the implementation file, after the imports, before #implementation):
#interface PictureListMainTable () <UITableViewDataSource, PictureListMainTableCellDelegate>
#end
(this extends the PictureListMainTable interface. It only extends it to specify privately that it conforms to these protocols.)
2) the NSNotification method
While I was typing out the above explanation, I decided it's my preferred way of doing things, so I would recommend doing it like that. There is the option of posting an NSNotification form your cell subclass, and observing for this notification from your main view controller. Just look into NSNotificationCenter, the following methods:
–postNotificationName:object:userInfo: (send the number in userInfo dictionary). Listen for it using –addObserver:selector:name:object:.
But like I said, option 1 is better, in my opinion.
Let me know if anything is unclear, good luck :)
EDIT: I really recommend reading this blog post to understand delegation: http://alexefish.com/post/15966868557/understanding-and-creating-delegates-in-objective-c

Passing data from UIView Controller textField to a TableViewController Label on a cell- Objective c

How can I pass textField data from a UIView Controller text field to a tableview label in a cell? I would like to somehow add the textfield data to an Array so that I can set the number of rows return value to the arrays count.
I've added an NSMutable array to my model.
In my view controller I'm implementing the prepareForSegue method
if ([segue.identifier isEqualToString:#"Details"]){
MileageDetailViewController * mdv = [segue destinationViewController];
NSString *text;
startTextField.text = text;
mdv.label.text = text;
I've tried this several different ways. I've done this with an array and tried to add text object an array but that didn't display either. This last way I tried using a label and adding the text from textField to a tableview Label.
In the tableView I add this code to grab the text from the viewController.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Reuse"];
UILabel *labe = (UILabel *) [cell viewWithTag:20];
labe.text = label.text;
// Configure the cell...
return cell;
You need to get comfortable with the MVC design pattern. Create a model class that holds the array. When the text field is modified, update the array. If the table view's view controller is observing the same model object (perhaps using KVO) then it can auto-update when the array changes.
The Code examples below are just to get you started. But I strongly, strongly recommend you follow the tutorials on Ray Wenderlich's site (link) as you seem to just be starting on iOS development.
Passing data between view controllers using prepareForSegue: (with comments in code block):
// This will get called before the view appears
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"Details"]) {
// Get destination view controller
MileageDetailViewController *vc = [segue destinationViewController];
// Grab the text field contents and put it into a public property on the new view controller
vc.myText = self.myTextField.text;
// NOTE: myText is a public NSString property on your MileageDetailViewController
// NOTE: self.myTextField is the IBOutlet connected to your Text Field
}
}
Now onto the methods in your controller with the table view:
// Load the model required for the view controller
- (void)viewDidLoad {
[super viewDidLoad];
// Load your "model" - in this case an array property (called myData) with a single piece of text
// NOTE: myText CANNOT be nil or an exception will occur
self.myData = [[NSArray alloc] initWithObjects: self.myText, nil];
}
// UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.myData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NOTE: You must have set the reuse identifier in Interface Builder for this to work
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Reuse"];
// NOTE: You must have set the tag in Interface Builder for this to work
UILabel *labe = (UILabel *)[cell viewWithTag:20];
labe.text = [self.myData objectAtIndex:indexPath.row];
return cell;
}
Hope this helps; iOS development is a lot of fun but following some tutorials will really help you get up-to-speed.

Resources