我有一个习惯UITableViewCell,有一个UILabel和一个UIImageView.我想在突出显示单元格时更改背景颜色和文本颜色.在我CustomCell的setHighlighted方法中,我有以下代码:
-(void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
if(self) {
if(highlighted) {
self.title.textColor = [UIColor whiteColor];
} else {
self.title.textColor = [UIColor blackColor];
}
//highlight background
UIView *bgColorView = [[UIView alloc] initWithFrame:self.frame];
bgColorView.backgroundColor = [UIColor blackColor];
[self setSelectedBackgroundView:bgColorView];
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试将代码textColor更改为tableView's didSelectRowAtIndexPath,但这不是我想要的效果 - 我希望文本颜色在用户触摸单元格时更改 - 而不是在触摸时.有什么建议?
我正在使用 AlamofireImage 将图像加载到 tableview 单元格中的 ImageView(在单独的 xib 文件中) 问题是图像永远不会显示。我认为代码是正确的,url 也是有效的。
这是代码(非常简单):
let placeholderImage = UIImage(named: "imgNoPhoto1")
if let urlImage = NSURL(string: urlString) {
photoImage.af_setImageWithURL(urlImage, placeholderImage: placeholderImage)
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?可能是单元格没有被重新加载?我已经在 iOS 8 和 9 中对其进行了测试。
希望你能帮帮我!谢谢
之间有什么区别setHighlighted和setSelected在UITableViewCell?
如果我只想cell在选择时不突出显示,我应该覆盖setHighlighter还是只设置selectionStyle为NONE.
在下面的返回的经典模式cell从dequeueReusableCellWithIdentifier总是非nil.为什么?我们不应该首先分配一些单元格,然后我们可以重新使用一些单元格吗?
我正在使用自定义单元格,它是在故事板中创建的.(但是,如果我使用了默认的UITableViewCell,则现象是相同的 - 返回的单元格仍然是non-nil).
环境:Xcode 4.3.3 iOs 5.1
AlbumListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AlbumCell"];
//cell always non nil --- why??
if(cell == nil){
cell = [[AlbumListCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"AlbumCell"];
}
Run Code Online (Sandbox Code Playgroud) 我正在以编程方式创建tableviews和单元格.tableview单元格分隔符在iOS 8中移动,

即使我已经设定:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return kSomeNumber;
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序是ios7,我的手机是ios8.可能是什么问题呢?我不能使用仅适用于ios8的cell.layoutMargins
我正在尝试以编程方式添加UITableView到现有的UIViewController.
我的run.h文件有这个:
@interface runTests : UIViewController <UINavigationControllerDelegate,UITextFieldDelegate,UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource> {NSTimer *Timer;}
@property (strong, nonatomic) UITableView *tableView;
Run Code Online (Sandbox Code Playgroud)
我的应用程序运行速度测试,在测试结束时,我正在尝试向View添加TableView.目前我有这个:
-(void)addSpeedTable {
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.tableView.rowHeight = 45;
self.tableView.sectionFooterHeight = 22;
self.tableView.sectionHeaderHeight = 22;
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"newCell";
UITableViewCell *cell = [tableView …Run Code Online (Sandbox Code Playgroud) 如何删除tvos中tableview单元格之间的默认空间?默认情况下,tvos 中 tableview 单元格之间的间隙为 14px,但我需要将空间增加 20px。
在StackOverflow上似乎已经多次询问过这个问题,但在搜索了几个小时之后,我仍然没有找到解决我问题的方法.
我在SecondViewController.swift中有一个表视图,我确实使它成为委托和dataSource SecondViewController.swift,但是当单击表格单元格时,仍然没有触发didSelectRowAt方法.我试图将segue应用于另一个视图控制器,但didSelectRowAt方法本身不起作用.
我在表视图属性的故事板中选择了单选,我确保为表视图和原型单元启用了用户交互.
对于下面的SecondViewController.swift,请假设allEvents填充到allEvents数组中.我能够成功填充它们并在表格中显示它们.唯一的问题是单击该行以执行segue.另外,请忽略下面的尴尬缩进.
SecondViewController.swift
import UIKit
class SecondViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
var allEvents: Array<JSON> = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
//self.tabBarItem.image = myTabImage
self.tabBarController?.tabBar.isTranslucent = false
self.tabBarController?.tabBar.barTintColor = UIColor(red:0.25, green:0.25, blue:0.25, alpha:1.0)
self.tabBarController?.tabBar.tintColor = UIColor.white
//ASSUME ALL EVENTS ARE POPULATED INTO allEvents
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose …Run Code Online (Sandbox Code Playgroud) 我ListView在我的项目中使用了Xamarin.Forms.我ViewCells用来显示数据.
现在,两个ViewCell之间有一条分隔线.有一种方法我可以删除它,以便两个ViewCells总是相互接触.
我尝试过使用SeperatorVisibility="None",但没有任何区别.
这是我的代码:
<ListView x:Name="AList"
StyleId="AList"
Grid.Row="0"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}"
IsVisible="{Binding IsProcessing, Mode=OneWay, Converter={StaticResource booleanNegationConverter}}"
SeparatorVisibility="None">
<ListView.BackgroundColor>
<OnPlatform x:TypeArguments="Color" iOS="Transparent" />
</ListView.BackgroundColor>
<ListView.RowHeight>
<OnPlatform x:TypeArguments="x:Int32" iOS="150" Android="150" WinPhone="170" />
</ListView.RowHeight>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell > .......</ViewCell></ListView>
Run Code Online (Sandbox Code Playgroud) 我有一个TableViewController,TableViewCell和一个ViewController.我在TableViewCell中有一个按钮,我想要呈现ViewController presentViewController(但是ViewController在storyboard上没有视图).我试过用:
@IBAction func playVideo(sender: AnyObject) {
let vc = ViewController()
self.presentViewController(vc, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
错误:TableViewCell类型的值没有成员presentViewController
然后,我试过了
self.window?.rootViewController!.presentViewController(vc, animated: true, completion: nil)
错误:警告:尝试显示其视图不在窗口层次结构中!
我究竟做错了什么?我应该怎么做才能从TableViewCell中呈现ViewController?另外,我如何将数据传递给TableViewCell的新呈现VC?
更新:
protocol TableViewCellDelegate
{
buttonDidClicked(result: Int)
}
class TableViewCell: UITableViewCell {
@IBAction func play(sender: AnyObject) {
if let id = self.item?["id"].int {
self.delegate?.buttonDidClicked(id)
}
}
}
----------------------------------------
// in TableViewController
var delegate: TableViewCellDelegate?
func buttonDidClicked(result: Int) {
let vc = ViewController()
self.presentViewController(vc, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:不建议在分离的视图控制器上显示视图控制器
(请注意,我在TableView后面有一个NavBar和TabBar链.)
我也试过了
self.parentViewController!.presentViewController(vc, animated: true, …Run Code Online (Sandbox Code Playgroud) tableviewcell ×10
ios ×7
uitableview ×6
objective-c ×4
swift ×2
tableview ×2
addsubview ×1
alamofire ×1
ios8 ×1
listview ×1
separator ×1
swift3 ×1
tvos ×1