我希望我的配件与正常情况略有不同.可能吗?此代码无效:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryView.frame = CGRectMake(5.0, 5.0, 5.0, 5.0);
Run Code Online (Sandbox Code Playgroud) 我创建这是越来越使用数组填充的详细披露按钮....然而accessoryButtonTappedForRowWithIndexPath:功能不被称为我的课.这是一个TableviewDelegate和TableviewDatasource委托.
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
NSLog(@"reaching accessoryButtonTappedForRowWithIndexPath:");
[self performSegueWithIdentifier:@"modaltodetails" sender:[self.eventsTable cellForRowAtIndexPath:indexPath]];
}
Run Code Online (Sandbox Code Playgroud)
NSLog没有打印到控制台,这使我相信函数没有被调用...这当然是我选择一个单元格.下面的屏幕截图显示了我如何设置单元格.

每当我将一个accessoryView添加到我的UITableViewCell时,它都没有背景颜色?我正在设置一个UISwitch作为我的accessoryView,我在cell.backgroundColor属性中设置的颜色只影响contentView而不影响accessoryView.我已经尝试了一切将它们设置为相同的值.我试图将cell.backgroundView.backgroundColor和cell.accessoryView.backgroundColor属性设置为我想要的颜色,但没有任何工作.我还尝试在contentView中创建一个子视图,它解决了backgroundColor问题(通过避免它),但它产生了问题,当文本太长时,开关位于cell.textLabel的顶部.
有没有办法在不在contentView中创建子视图的情况下修改accessoryView的背景颜色,或者在没有子类化UITableViewCell的情况下改变cell.textLabel的长度?
我正在尝试将uiview添加到键盘顶部.我首先使用KeyboardWillShow/Hide完成了它,但它并未涵盖所有情况,我正在尝试使用inputAccesoryView.这是我试过的:
private var accessoryView = UIView(frame: CGRectZero)
class ViewController : UIViewController {
var myView: customUIView
override var inputAccessoryView: UIView {
return accessoryView
}
override func canBecomeFirstResponder() -> Bool {
return true
}
override func viewDidLoad() {
super.viewDidLoad()
accessoryView = myView
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:由于未捕获的异常'UIViewControllerHierarchyInconsistency'终止应用程序,原因:'子视图控制器:UICompatibilityInputViewController应该有父视图控制器:MyViewController但请求父级是:UIInputWindowController:'
任何帮助将不胜感激!
我试图设置我的UITableViewCells的单元格背景,但我正在努力与UIAccessoryView的背景颜色.它没有改变.
任何人都可以帮助我使UIAccessoryView的背景颜色透明(或实际上任何其他颜色)?
这是我的代码
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.accessoryView.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if(indexPath.row % 2) {
cell.contentView.backgroundColor = [UIColor clearColor];
}
else {
cell.contentView.backgroundColor = [UIColor redColor];
}
Run Code Online (Sandbox Code Playgroud)
这是一个说明问题的图像

我完全不确定为什么我的配件视图不起作用.我只是希望一些文本出现在UITableViewCell(以及左侧)的右侧,但只显示左侧的文本.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell"];
if (cell==nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"SwitchCell"] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 60, 30)];
cell.textLabel.text = @"left text";
label.text = @"right text";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryView = label;
[label release];
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢.
我正在使用iOS Swift 2.0应用程序.我无法弄清楚我的生活如何UITableViewCell在披露指标雪佛龙之前的右侧设置文本(除了创建自定义cell.accessoryView).
这是"设置应用程序"的屏幕截图,正是我正在努力实现的目标.
我正在尝试创建一个accessoryInputView来增加键盘的一些应用程序特定的键.
我正在使用基于Storyboard的设计方法来保持UI与应用程序逻辑分离.
我似乎无法理解如何创建新视图并将其与textView相关联.可能吗?
我创建了一个带有UITableView和静态 UITableViewCells的UITableViewController.
如何在UIImageView中将附件视图更改为自定义图像?
我知道如何更改附件视图:
UIImage *accessor = [UIImage imageNamed:@"imageName"];
[somecell setAccessoryView:[[UIImageView alloc] initWithImage: accessor]];
Run Code Online (Sandbox Code Playgroud)
解决方案:
为每个UITableViewCell创建一个IBOutlet,它应具有自定义附件视图,并将IBOutlet连接到故事板中的UITableViewCell.之后,您可以像上面一样设置配件视图.
我有一个带有自定义单元格的 UITableView。通常当用户点击单元格时,会触发此功能:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//Segue to another view
}
Run Code Online (Sandbox Code Playgroud)
如果在该视图中他们将单元标记为已完成,则当他们返回代码时将添加标准检查附件。
当单元格未完成时,我想要一个可以点击的空支票(我知道我可以添加自定义图像附件),点击允许用户跳过转场并快速将单元格标记为已完成。但我似乎无法让两者都工作:
我已经尝试过accessoryButtonTappedForRowWithIndexPath,但它似乎没有被调用。
func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
//Shortcut code to change the cell to "finished"
}
Run Code Online (Sandbox Code Playgroud)
是否可以单击主体触发一组代码,单击附件视图触发另一组代码?如果是这样,怎么办?
accessoryview ×10
ios ×8
uitableview ×8
iphone ×3
swift ×3
objective-c ×2
cocoa-touch ×1
sdk ×1
storyboard ×1