我有几个本地html文件,我想在静态(现在)单元格的表中显示它们.每个UIWebView都有不同的高度(我不想在UIWebView中有任何滚动)所以显然每个单元格都有不同的高度.我读到的大多数评论都不鼓励在表格单元格中使用UIWebView.您怎么看:这适用吗?是否会很慢并需要时间加载?
我想更改此代码:
override func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
}
Run Code Online (Sandbox Code Playgroud)
像那样:
override func tableView(tableView: UITableView, didEndDisplayingCell cell: CustomCell, forRowAtIndexPath indexPath: NSIndexPath) {
}
Run Code Online (Sandbox Code Playgroud)
但是我收到一条错误消息.当它消失时,我需要更改我的CustomCell.我怎么处理这个?
我有一个tableView.当点击/选择单元格时,单元格向下展开以显示多个资产.一个资产是文本字段.另一个是"提交"按钮.
当按下Submit按钮时,我需要从文本字段访问用户输入.我怎样才能做到这一点?
重要提示:由于已经选择/扩展了单元格,因此无法使用didSelectRowAtIndexpath.
目前我在customCell上有以下内容:
@IBAction func submitButtonPressed(sender: UIButton) {
// prepareForSegue is on mainVC
self.textString = self.textField.text
println(self.textString)
}
Run Code Online (Sandbox Code Playgroud)
在MainVC的"prepareForSegue"中,我有以下内容:
var cell : CustomCell = self.tableView.dequeueReusableCellWithIdentifier("myCell") as! CustomCell
let path = self.tableView.indexPathForSelectedRow()!
println(cell.textField.text)
self.newText = cell.textString
self.newInt = self.newText.toInt()
println(self.newText)
println(self.newInt)
Run Code Online (Sandbox Code Playgroud)
以下代码正确prints(self.textString)
然而
cell.textString,self.newText并且self.newInt始终如此nil.
知道为什么吗?
对于提要视图控制器,我有一个带有一些自定义单元格的表格视图,这些单元格具有用于点赞、评论和分享的按钮,我想根据按下的按钮执行不同的操作。
我最初的想法是简单地将故事板中自定义单元格中的按钮连接到自定义单元格中的操作方法。但是,我对自定义单元格 .m 文件中的方法如何与视图控制器中的 TableView 交互感到困惑。
- (IBAction)likeButtonPressed:(id)sender {
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
//do something
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以澄清是否可以在情节提要中连接单元格中的按钮,以及这如何与视图控制器、cellforrowatindexpath 和 didselectrowatindexpath 上的委托方法一起播放?
或者,如果这不是正确的方法,将不胜感激任何关于更好方法的建议。在此先感谢您的任何建议。
我正在尝试将一个自定义单元格加载到一个UITableView并且它不断抛出错误
UITableView dataSource必须从tableView:cellForRowAtIndexPath返回一个单元格:
我不知道为什么.我已将我的表视图单元格链接到我的代码中的UITableViewCell定义,但它一直给我这个错误.这是我的代码; 任何帮助将不胜感激.
#import "RegisterDeviceViewController.h"
@implementation RegisterDeviceViewController
@synthesize checkString;
@synthesize cellRegistration;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
//Change UITableView Style to Grouped
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to …Run Code Online (Sandbox Code Playgroud) 我正在尝试初始设置UITableViewCellin将显示单元格,但它不起作用.谁能帮我吗?
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.awtxt.font = [UIFont fontWithName:@"Helvetica" size:15.0]; //i am unable to set this .awtxt is the property outlet in my custom ui table view cell named as "postCell"
}
Run Code Online (Sandbox Code Playgroud) cellForRowAtIndexPath当我尝试创建自定义表格单元格时,我的程序在方法中不断崩溃。我在代码的每一行都放置了一个断点,在我尝试创建带有错误 的单元格变量后代码失败:unexpectedly found nil while unwrapping optional value。我以前曾多次成功使用自定义表格单元格,但从未遇到过此问题。这看起来很简单,但我无法弄清楚出了什么问题。也许 xcode 中的某些内容发生了我不知道的变化?任何帮助表示赞赏。谢谢!...此外,我确实在viewDidLoad. 我也会包含该代码。
var nib = UINib(nibName: "FeedTableViewCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "feedCell")
Run Code Online (Sandbox Code Playgroud)
问题代码如下:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:FeedTableViewCell = tableView.dequeueReusableCellWithIdentifier("feedCell", forIndexPath: indexPath) as! FeedTableViewCell
cell.descriptionLabel.text = "Testing the description label of my cell."
return cell
}
Run Code Online (Sandbox Code Playgroud)
更新
这个项目和其他已经成功的项目之间的一个区别是 Xcode 现在提示我在 as 后面放一个 bang (!),而之前我从未使用过。如果我不添加 (!) 它会给我错误消息“AnyObject 不可转换为FeedTableViewCell”
作为!FeedTableViewCell- 而不是 - 作为FeedTableViewCell
FeedTableViewCell …
//自定义单元格在一个swift文件中
import UIKit
class CardTableViewCell: UITableViewCell {
@IBOutlet weak var elapsedTime: UILabel!
@IBOutlet weak var todo: UILabel!
@IBOutlet weak var startAndStop: UIView!
@IBOutlet weak var progress: UIView!
@IBOutlet weak var cardView: UIView!
}
Run Code Online (Sandbox Code Playgroud)
//自定义表视图控制器在另一个swift文件中
import UIKit
class CardFeedTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(CardTableViewCell.self, forCellReuseIdentifier: "cardCell")
tableView.delegate = self
tableView.dataSource = self
}
// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number …Run Code Online (Sandbox Code Playgroud) 场景:我有一个表格视图和一个自定义按钮单元。在单元格的控制器中,我已委托一个函数调用MainController的函数。问题是我的单元格按钮动作正在触发,但删除功能却未触发。
CustomCell控制器:
import UIKit
protocol CustChatButtonDelegate: class {
func chatActionClick(cell: CustButtonCell)
}
class CustButtonCell: UITableViewCell {
var delegete:CustChatButtonDelegate?
@IBOutlet weak var btnChat: UIButton!
override func prepareForReuse() {
super.prepareForReuse()
// self.delegete=nil
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
@IBAction func btnChatActionClick(_ sender: Any) {
print("btn click")
self.delegete?.chatActionClick(cell: self)
}
}
Run Code Online (Sandbox Code Playgroud)
主控制器:
import UIKit
class ChatController: UIViewController ,UITableViewDelegate, UITableViewDataSource, …Run Code Online (Sandbox Code Playgroud) custom-cell ×9
uitableview ×7
ios ×6
swift ×5
objective-c ×2
cocoa-touch ×1
datasource ×1
iphone ×1
nsindexpath ×1
segue ×1
tableview ×1
uiwebview ×1