Storyboards Tutorial 04

Source: Internet
Author: User

After the design of the run found no change, is blank. This is because your TableView-related delegate method is still there. So the first thing to do is to block or remove the following actions in playerdetailsviewcontroller.m

#pragma mark-table View data source

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {
#warning potentially incomplete method implementation.
Return the number of sections.
return 0;
}

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {
#warning incomplete method implementation.
Return the number of the rows in the section.
return 0;
}

And then it works again!

But you will find that because there is margin before you drag TextField, there will be a point where the user clicks the edge, keyboard will not appear. This will mislead the user into thinking there is a problem. So we need to add the following method to activate Nametextfield when the user clicks on the first section.

Set the cell's property selection Style to None, or the user will see a highlight when they click on the TextField.

The ADD Player screen at work

When the user chooses to finish, a new player object needs to be created to save. In playerdetailsviewcontroller.m

#import "Player.h"

-(ibaction) Done:(Id) Sender* Player = [[player alloc = self.nameTextField.text; player.game = Span style= "color: #11740a; Font-style:italic; " >@= 1; [self.delegate playerdetailsviewcontroller:self Didaddplayer:p layer]; 
PlayerDetailsViewController.h
@class Player;@protocol playerdetailsviewcontrollerdelegate <NSObject>-(void) Playerdetailsviewcontrollerdidcancel:(playerdetailsviewcontroller *) controller;  - (void) Playerdetailsviewcontroller:(playerdetailsviewcontroller *) controller Didaddplayer:(Player *) player;  @end
In playersviewcontroller.m
-(void) Playerdetailsviewcontroller:(Playerdetailsviewcontroller*) Controller Didaddplayer:(Player*) player{[Self.players AddObject:p Layer];Nsindexpath *indexpath=[NsindexpathIndexpathforrow:([Self.players Count]-1) insection:0[self.tableview insertrowsatindexpaths:@[indexpath :uitableviewrowanimationautomatic [self dismissviewcontrolleranimated:yes completion:nil 
This will insert a new record each time you choose to finish, as well as an animated effect.
Note: Storybord does not instantiate all view controllers, only the initial view controller is instantiated. Other view controllers are not instantiated until you segue them. When you close these view controllers, they are destroyed immediately. So only the view controller that is currently active will remain in memory.

< Span style= "color: #a61390;" >< Span style= "color: #002200;" > You can test the period of a view controller with the following code

< Span style= "color: #a61390;" >< Span style= "color: #002200;" >

Note: Static cells can only be UITableViewController used in embedding. Although the program will allow you to embed this static cells into UIViewController a table view object in. When run, it is saved.

Xcode will even make an error in your compilation, "Illegal configuration:static table views is only valid if embedded in Uitableviewcontroller instance  S ". Cells of the Prototype cells type are only normally used in a common uiviewcontroller embedded table view.

The Game picker screen

Drag a new Uitable view controller and use CTRL + Drag to connect to the previous game Cell,segue select Push. The identifier of segue is set to pickgame. Double-click Navigation bar in the new Table view to change the display to Choose Game. Modify the type of cell to Basic. Sets the reuse identity symbol Gamecell.

Create a new file Gamepickerviewcontroller inherit from Uitableviewcontroller. and set the class of UITableView to GamePickerViewController .

gamepickerviewcontroller.m: Medium

Then add a new proxy to transfer the data

In the GamePickerViewController.h

Add in gamepickerviewcontroller.m

In PlayerDetailsViewController.h

#import "GamePickerViewController.h"
: Uitableviewcontroller <GamePickerViewControllerDelegate>

In playerdetailsviewcontroller.m
@implementation Playerdetailsviewcontroller{    nsstring*_game;}

-(Id) Initwithcoder:(Nscoder *) Adecoder{if  ( (self = [super Initwithcoder:adecoder) ) {Nslog (@ "Init Playerdetailsviewcontroller "); _game = @ return self;} 

/span>
(void) viewdidload{    [super viewdidload= _game;}     
-(void) Prepareforsegue:(Uistoryboardsegue*) Segue Sender: (id{if  ([ Segue.identifier isequaltostring: @ ]) {gamepickerviewcontroller  *gamepickerviewcontroller = Segue.destinationviewcontroller; Gamepickerviewcontroller.delegate = self; gamepickerviewcontroller.game = _game; } 

/span>
-void) Gamepickerviewcontroller: ( Gamepickerviewcontroller *) controller didselectgame< Span style= "color: #002200;" >: (nsstring  *< Span style= "color: #002200;" >) Game{_game = game; Self.detailLabel.text = _game;  [self.navigationcontroller Popviewcontrolleranimated:yes 

/span>
-(ibaction) Done:(id{Player Span style= "color: #002200;" >*player = [[player Alloc= self.nameTextField.text; player.game = _ Game //only the line is changed player.rating = 1;  [self.delegate Playerdetailsviewcontroller:self didaddplayer: Player 

/span>

Storyboards Tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.