看板 MacDev 關於我們 聯絡資訊
也是最近才入手一台MAC,本來就很想試試寫iOS的程式, 所以也不廢話的裝了Xcode,買了一本Objective-C的書來看, 不過看完以後發現這本書大部分都在講Objective-C的語法(廢話) 實際上用到iOS上還有點差距(好像java和Android一樣), 於是我實際開始用Xcode寫iPhone的時候發生很多無法理解的問題... 最基本的使用一個class,我也只是想測試一下要怎麼用而已, 很簡單但是什麼都沒出來...我的專案是這樣: 開一個Single View,然後新增一個Objective-C Class classtest classtest.h是這樣: #import <Foundation/Foundation.h> @interface classtest : NSObject @property NSString *name; @property int number; @end classtest.m是這樣: #import <"classtest.h"> @implementation classtest @synthesize name, number; @end 主程式ViewController.h是這樣: #import <UIKit/UIKit.h> #import "classtest.h" @interface ViewController : UIViewController @property (strong, nonatomic) IBOutlet UILabel *show; -(IBAction)btn:(id)sender; @property classtest *classer; @end ViewController.m是這樣: #import "ViewController.h" //稍略 @synthesize show, classer; -(IBAction)btn:(id)sender { show.text = classer.name; } //下略,在load裡面有給classer.name值 大概是這樣,很簡單的一個小專案而已, View上有一個Label(show)和Button(btn) 照理來說按下btn就會讓show的text為classer的name, 但我這樣寫按下去會什麼都沒有QQ show直接變空的, 我也有嘗試過讓class有初始值,但仍然什麼都沒出來... 讓我百思不得其解,程式看起來好像是認不得這個class, 但編譯又能通過,說明應該是沒問題的啊... 只好來板上問問看...這好像是基本到不行的問題...拜託各位了orz -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.162.166.46 ※ 編輯: stu87616 來自: 1.162.166.46 (10/28 22:23)
yodxxxd:@property classtest @classer; 這行是?? 10/28 22:50
yodxxxd:@property (strong, nonatomic) classtest *classer; 10/28 22:52
yodxxxd:這樣試試看? 10/28 22:52
啊對,是我筆誤了,原本是 *classer 加了(strong, nonatomic)以後還是一樣都沒東西ˊ_ˋ...
chchwy:因為你需要第二本書 專門講iOS開發 10/28 23:20
請問有推薦嗎? 我買的是精通Objective-C程式設計第四版 因為是中文的-3-.... ※ 編輯: stu87616 來自: 1.162.166.46 (10/29 00:25) ※ 編輯: stu87616 來自: 1.162.166.46 (10/29 00:57)
tentenlee:你需要的是寫IOS的書 OBJ-C只是基礎 重點還是在IOS的書 10/29 01:58
tentenlee:OBJ-C只是一個語法 不代表會OBJ-C就會寫IOS APP 10/29 01:59