如何在xcode中使用storyboard

 我来答
就烦条0o
2018-08-03 · 知道合伙人软件行家
就烦条0o
知道合伙人软件行家
采纳数:33315 获赞数:46497
从事多年系统运维,喜欢编写各种小程序和脚本。

向TA提问 私信TA
展开全部
一、如何使用storyboard简单实现Push页面,步骤如下:
1、创建一个带有storyboard的singleview application应用程序。
创建好的应用程序已经自动创建好了一个和MainStoryboard连接好的ViewController。
2、在MainStoryboard中,选中ViewController并拖入tableview以及tableviewCell,并且设置tableviewCell的style为Basic,Identifier为Cell,如果希望是自定义cell的则需要选择custom,如下图,之后可以插入一个NavigationController:
不要忘记连接datasource和delegate。
现在可以编码了,在ViewController.m中:
#pragmamark - UITableViewDataSource
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return1;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
staticNSString*CellIdentifier = @"Cell";
UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell= [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text=@"话题";
returncell;
}
3、现在实现简单的push功能:
再次打开MainStoryboard文件,新拖入一个TableViewController,并且在右边工程中新建一个TopicTableViewController的h文件和m文件,选中MainStoryboard中的TableViewController,将其class设置为TopicTableViewController,同上设置好tableview的cell。
*右键选择前一个viewcontroller的cell,连接push到新拖入的TableView Controller:
这个时候运行就能正确push到新的tableview页面了。
如果你希望在push页面的时候做些什么操作的话,可以在ViewController.m文件中编码:
-(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
if([[segueidentifier]isEqualToString:@"showSomething"]){
//dosomething you want
UIAlertView*alertView = [[UIAlertViewalloc]initWithTitle:nilmessage:@"test"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
[alertViewshow];
}
}
记住一定要设置push的segue,在这里我设置为showSomething。
运行可以看到在push页面的同时弹出了testalert框,
二、获取指定storyboard中的object
前面的步骤按照第一、二步完成,然后第三步完成到*符号之前,这个时候看到的就是一个单独的新建的tableview controller,怎么获取它呢?很简单,首先,MainStoryboard中选中新建的tableview controller,设置其identifier为TopicTableViewController,
接着,在你需要使用它的函数里,如下:
-(void)presentTimelineViewController:(BOOL)animated
{
UIStoryboard*storyboard = [UIStoryboardstoryboardWithName:@"MainStoryboard"bundle:nil];
TopicTableViewController*topicViewController = [storyboardinstantiateViewControllerWithIdentifier:@"TopicTableViewController"];
。。。
[self.navigationControllerpushViewController:topicViewControlleranimated:animated];
}
战慷链
2016-06-23 · TA获得超过150个赞
知道答主
回答量:318
采纳率:33%
帮助的人:137万
展开全部
配置maven环境变量 M2_HOME:D:\workspace\maven\apache-maven-3.0.5 Path:;%M2_HOME%/bin; 检查是否成功,打开CMD: Mvn -v mvn install 会将项目生成的构件安装到本地Maven仓库 mvn deploy 用来将项目生成的构件分发到远程Maven仓库 D:\>mvn ...
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式