Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想通过它所标记的名称而不是索引来选择段,setSelectedSegmentIndex:0我也不想通过并手动定义带有标记名称的每个索引。我怎样才能做到这一点?
setSelectedSegmentIndex:0
刚刚为此创建了一个类别,您可以在 GitHub 上找到它。
只需在要使用它的文件中导入类别,然后:
[yourControl selectSegmentCalled:@"The Name"];
这不值得 - 使用索引:
NSString* title = @"My Title"; for (int i = 0; i < control.numberOfSegments; i ++) { if ([[control titleForSegmentAtIndex:i] isEqualToString:title]) { control.selectedSegmentIndex = i; break; } }