我有一个表格 View ,可以通过按下工具栏中的按钮来加载不同的数据。所以我想做的是隐藏段控件并在按下某个按钮时显示标题,如果按下另一个按钮则反之亦然。
我的段控件名为 sortButton,我将其隐藏
sortButton.hidden = TRUE
并用
显示sortButton.hidden = FALSE
所以当按钮被隐藏时,我想在它的位置有标题。知道如何解决这个问题。
我试过简单的
self.title = @"Restavracije";
或
self.navigationItem.title = @"Restavracije";
但标题没有出现
最佳答案
我为您制作了一个简约的演示项目,它说明了如何完成您想要的。
这是相关代码:
@interface HASTableViewController ()
@property (strong, nonatomic) UISegmentedControl *sortButton;
@property (copy, nonatomic) NSArray *dataSource1;
@property (copy, nonatomic) NSArray *dataSource2;
@property (copy, nonatomic) NSArray *dataSource3;
@end
@implementation HASTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Create the segmented control
self.sortButton = [[UISegmentedControl alloc] initWithItems:@[@"First", @"Second", @"Hide me"]];
[self.sortButton addTarget:self action:@selector(switchDataInTableView) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = self.sortButton;
self.sortButton.selectedSegmentIndex = 0;
// We set the title you want to show when the segmented control is "hidden"
self.navigationItem.title = @"Sort Button is nil.";
// Setup a data source
self.dataSource1 = @[@"First", @"First", @"First", @"First", @"First", @"First", @"First", @"First", @"First", @"First", @"First"];
// and another one
self.dataSource2 = @[@"Second", @"Second", @"Second", @"Second", @"Second"];
// Create a third datasource which contains both arrays
NSMutableArray *tempDataSourceArray3 = [[NSMutableArray alloc] initWithArray:self.dataSource1];
[tempDataSourceArray3 addObjectsFromArray:self.dataSource2];
self.dataSource3 = tempDataSourceArray3;
}
- (void)switchDataInTableView {
// Reload the table view.
// tableView:cellForRowAtIndexPath decides which datasource to show
[self.tableView reloadData];
// If it is "Hide it" we hide
if (self.sortButton.selectedSegmentIndex == 2) self.navigationItem.titleView = nil;
}
#pragma mark - UITableView Data Source Methods
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// We use the standard cell
UITableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
// If "First" is selected we want the text to be taken fromt the dataSource1 array
tableViewCell.textLabel.text = self.sortButton.selectedSegmentIndex == 0 ? self.dataSource1[indexPath.item] : self.sortButton.selectedSegmentIndex == 1 ? self.dataSource2[indexPath.item] : self.dataSource3[indexPath.item];
return tableViewCell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// return number of rows
return self.sortButton.selectedSegmentIndex == 0 ? self.dataSource1.count : self.sortButton.selectedSegmentIndex == 1 ? self.dataSource2.count : self.dataSource3.count;
}
@end
关于ios - 按下按钮时显示标题而不是段控件 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20173708/
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数
我有一张背景图片,我想在其中添加一个文本框。我想弄清楚如何将标题放置在其顶部的正确位置。(我使用标题是因为我需要自动换行功能)。现在,我只能让文本显示在左上角,但我需要能够手动定位它的开始位置。require'RMagick'require'Pry'includeMagicktext="Loremipsumdolorsitamet"img=ImageList.new('template001.jpg')img 最佳答案 这是使用convert的ImageMagick命令行的答案。如果你想在Rmagick中使用这个方法,你必须自己移植
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我希望用户从一个模型的三个选项中选择一个。即我有一个模型视频,可以被评为正面/负面/未知目前我有三列bool值(pos/neg/unknown)。这是处理这种情况的最佳方式吗?为此,表单应该是什么样的?目前我有类似的东西但显然它允许多项选择,而我试图将它限制为只有一个..怎么办? 最佳答案 如果要使用字符串列,让我们说rating。然后在你的表单中:#...#...它只允许一个选择编辑完全相同但使用radio_button_tag: 关于ruby-on-rails-Rails单选按钮-模
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
如果names为nil,则以下中断。我怎样才能让这个map只有在它不是nil时才执行?self.topics=names.split(",").mapdo|n|Topic.where(name:n.strip).first_or_create!end 最佳答案 其他几个选项:选项1(在其上执行map时检查split的结果):names_list=names.try(:split,",")self.topics=names_list.mapdo|n|Topic.where(name:n.strip).first_or_create!e
有没有办法跳过CSV文件的第一行,让第二行作为标题?我有一个CSV文件,第一行是日期,第二行是标题,所以我需要能够在遍历它时跳过第一行。我尝试使用slice但它会将CSV转换为数组,我真的很想将其读取为CSV,以便我可以利用header。 最佳答案 根据您的数据,您可以使用另一种方法和skip_lines-option此示例跳过所有以#开头的行require'csv'CSV.parse(DATA.read,:col_sep=>';',:headers=>true,:skip_lines=>/^#/#Markcomments!)do|