Title5

Title5

1.ViewController砍掉,把storyboard的viewcontroller砍掉
2.建一個cocotouch class –>shopping list繼承於UIviewcontroll
3.在storyboard拉一個viewcontroller建立init 進入點
4.在viewcontroller繼承
5.再拉一個tableviewcontroller
5-1 建一個mytableview繼承自UItableViewController
5-2設定custom class繼承自mytableview

6.再拉一個navigation bar
7.建bar button item
8 table view cell 的ideterfiy 設定為Cell
8-1.建一個MyTableViewcellCell繼承自UIviewcontrollercell

9.建立一個class 叫做rows 繼承自NSObject

10 X

11建立iboutlet跟ibaction在shoppingList.m
11-1三個
12.在rows宣告變數

@interface Rows : NSObject
@property(strong,nonatomic)NSString*rowsItems;
@property(nonatomic) int rowsPrice;
@property(nonatomic) int rowsNnumber;

12-1

import “Rows.h”

12-2
- (IBAction)submit:(UIButton *)sender {
Rows*rows=[[Rows alloc]init];
rows.rowsItems=self.itemsText.text;
rows.rowsPrice=self.priceText.text.intValue;
rows.rowsNnumber=self.numberText.text.intValue;

14.
@property(nonatomic,strong)NSMutableArray*sendArray;
建立在shoppinglist.h

15.
建立在button內
self.sendArray=(NSMutableArray*)@[rows];

16.

import “MyTableViewController.h”

17.
MyTableViewController.h
@property(strong,nonatomic)NSMutableArray *list;

18.
//傳值過去MytableviewController內
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
MyTableViewController* vc= segue.destinationViewController;
vc.list=self.sendArray;

}

19.MyTableViewController.m

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //#warning Incomplete implementation, return the number of rows
    return self.list.count;
    }

20.

import “MyTableViewCell.h”

21

//MyTableViewCell

  • (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”Cell” forIndexPath:indexPath];

    // Configure the cell…

    return cell;
    }

22.#import “Rows.h”

  1. Rows* rows =self.list[indexPath.row];//rows = section variable
    int sum = rows.rowsPrice * rows.rowsNnumber;

24.建立三個label
25.建立在MyTableViewCell.h

26.然後繼續寫MyTableViewController.m
int sum = rows.rowsPrice * rows.rowsNnumber;
cell.itemsLabel.text=rows.rowsItems;
cell.numberLabel.text= [NSString stringWithFormat:@”%d”,rows.rowsNnumber];
cell.PriceLabel.text= [ NSString stringWithFormat:@”%d”,sum ];

Comments

Popular posts from this blog

MEGA 暫存檔案刪除

XAMPP 使用多PORT來執行不同網頁

IOS GCD多執行緒