Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks for answers. Let's say i'm new to programming in Xcode and i have to understand better delegates. i used the template and i modified just a couple of things.so i had this <strong>masterviewcontroller.m</strong></p> <pre><code>@interface MasterViewController () { NSMutableArray *_objects; } @end @implementation MasterViewController @synthesize returnedItem; -(void) addItemViewController:(id) controller didFinishEnteringItem: (NSString *)item { returnedItem = item; NSLog(@"This was returned from secondPageViewController"); } - (void)viewDidLoad { [super viewDidLoad]; // 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:)]; self.navigationItem.rightBarButtonItem = addButton; } //create new cell - (void)insertNewObject:(id)sender { if (!_objects) { _objects = [[NSMutableArray alloc] init]; } [_objects insertObject:[NSDate date] atIndex:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } #pragma mark - Table View - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _objects.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; CGRect frame = CGRectMake (68, 12, 225, 22); UITextField *textfield = [[UITextField alloc] initWithFrame:frame]; [self setNameField:textfield]; [_nameField setDelegate:self]; [_nameField setReturnKeyType:UIReturnKeyDone]; [_nameField addTarget:self action:@selector(textFieldFinished:) forControlEvents:UIControlEventEditingDidEndOnExit]; [cell.contentView addSubview: _nameField]; cell.textLabel.enabled = YES; cell.accessoryType = UITableViewCellAccessoryNone; return cell; } - (void)textFieldFinished:(id)sender{ [sender resignFirstResponder]; } - (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [_objects removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } } - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { NSString *title = [_objects objectAtIndex: [fromIndexPath row]]; [_objects removeObjectAtIndex:[fromIndexPath row]]; [_objects insertObject:title atIndex:[toIndexPath row]]; [[self tableView] reloadData]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showDetail"]) { NSString *object = _nameField.text; [[segue destinationViewController] setDetailItem:object]; } } @end </code></pre> <p>i don't know where to define delegate.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload