Re: [問題] tableview 無法Reloaddata + Reject抱怨

看板MacDev作者 (天天)時間12年前 (2013/02/01 09:05), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《elver (elver)》之銘言: : 不好意思小弟才剛入門, : 想詢問一下關於tableview reloaddata 的問題 : 在此先說一聲謝謝~~ : 在程式啟動後,table的確會照plist內的數量而建, : 我也確定按下 add按鈕後,array的確有增加而且存進plist內, : 因為關掉程式後再開啟,table就是plist的數量, : 問題是 "我按reload那顆按鈕,tableview不會更新" : 所以想問一下.我有那裡弄錯... : --------------------------------------------------- : 這是我的 .h檔 : @interface ViewController :UIViewController : <UITableViewDataSource,UITableViewDelegate> : { : UITableView *tableView; : } : @property (nonatomic,retain)UITableView *tableView; : @end : ---------------------------------------------------- : ---------------------------------------------------- : 以下是我的 .m檔(不含tableview建置部分及array存取plist部分 ) : @interface ViewController () : { : NSMutableArray *array; ///拿來建置tableview的array : } : @end : @implementation ViewController : @synthesize tableView; : - (void)viewDidLoad : { : [super viewDidLoad]; : array = [[NSMutableDictionary alloc] init]; : array=[self takePlist]; ///將plist內資料讀出到array : ///布置一層view : UIView *overlayView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)]; : ///建tableview : UITableView *tableView = [[UITableView alloc]initWithFrame: : CGRectMake(0,0,320,480) style:UITableViewStylePlain]; 重點在這行 這不是你前面所宣告的tableview 你又建立了一個名叫tableview的tableview 把它改成 self.tableView = [[UITableView alloc]initWithFrame: CGRectMake(0,0,320,480) style:UITableViewStylePlain]; 應該就可以了 有提到tableview的地方都改這樣 上面有幾篇文章在講setter跟getter的觀念 請看一下 你有synthesize所以應該是要用self.tableview但是你又宣告了一個tableview 然後在method裡面又在宣告了一個tableview 請習慣在synthesize物件的時候多加=_ 例: @synthesize myTableView=_myTableView; 這樣你再用setter跟getter的時候他就會跟你說錯誤 久了你就會習慣了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.84.254.121 ※ 編輯: tentenlee 來自: 219.84.254.121 (02/01 09:08)

02/01 09:53, , 1F
可以relod了,感謝
02/01 09:53, 1F

02/01 22:31, , 2F
現在已經不用加在synthesize的時候指定iVar囉
02/01 22:31, 2F

02/01 22:31, , 3F
compiler會自動幫你加 _xxxxx
02/01 22:31, 3F

02/02 02:42, , 4F
痦{在在修改舊專案 她不會幫我家 所以我還是會手動
02/02 02:42, 4F
文章代碼(AID): #1H2nJVEn (MacDev)
文章代碼(AID): #1H2nJVEn (MacDev)