作者aureolus (Aureo)
看板MacDev
标题[问题] 请益从其他class获取参数的方法
时间Mon Mar 28 15:00:35 2016
假设在MAC OS X开发应用APP下
我在A.h中宣告了
IBOutlet NSPopUpButton *popupBut;
并在A.m中写了
NSString *select1 = [NSString stringWithFormat:@"%@",[popupBut titleOfSelectedItem];
请问如果我要在B.m中得到A.m的NSPopUpButton *popupBut的值
该怎麽写才好?试了多次爬了一些文由A.m中得到的值都是NULL
谢谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.248.134.2
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MacDev/M.1459148438.A.051.html
1F:→ LFimi: 你确定是同一个instance? 03/28 15:29
2F:→ uranusjr: 资讯不足, 可能性太多, 请附上更详细的程式码 03/28 15:56
谢谢两位帮忙,大概就是把A.h下宣告的NSPopUpButton在B.m中
取得NSPopUpButton里面字串资讯这样
比方说在A.h中宣告
IBOutlet NSPopUpButton *popupBut;
然後我在B.m中@import "A.h"後宣告
A *smA = [A alloc];
NSString *getstring =
[NSString stringWithFormat:@"%@",[smA.popupBut titleOfSelectedItem];
来让getstring抓到A.h NSPopUpButton的值这样
抱歉一开始没有说得很清楚,谢谢!
※ 编辑: aureolus (60.248.134.2), 03/28/2016 17:41:03
3F:→ yuanruo: 你应该是要把a的instance传给b而不是再b alloc新的 03/28 18:41
4F:推 Blueshiva: 你要在Storyboard把popupBut Link到某个NSPopUpButton 03/29 01:30
5F:→ howdiun: [NSStoryboard storyboardWithName:@"XXX" bundle:nil]; 03/29 09:20
6F:→ howdiun: [storyboard instantiateControllerWithIdentifier:XXX]; 03/29 09:21
7F:→ howdiun: button是storyboard帮你产生的,否则他从头到尾都是null 03/29 09:25
谢谢各位的帮忙,以用上述的方向成功解决了问题,谢谢大家!
※ 编辑: aureolus (60.248.134.2), 03/29/2016 13:34:13