我正在尝试为在表视图单元格中按下的按钮运行操作.以下代码在我的表视图控制器类中.
该按钮在我的UITableViewCell类中称为requestsCell的插座中被描述为"是".
我正在使用Parse来保存数据,并希望在按下按钮时更新对象.我的objectIds数组运行正常,cell.yes.tag也会将正确的数字打印到日志中,但是,为了正确运行我的查询,我无法将该数字输入我的"连接"函数.
我需要一种方法来获取单元格的indexPath.row以找到正确的objectId.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as requestsCell
// Configure the cell...
cell.name.text = requested[indexPath.row]
imageFiles[indexPath.row].getDataInBackgroundWithBlock{
(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
let image = UIImage(data: imageData)
cell.userImage.image = image
}else{
println("not working")
}
}
cell.yes.tag = indexPath.row
cell.yes.targetForAction("connected", withSender: self)
println(cell.yes.tag)
return cell
}
func connected(sender: UIButton!) {
var query = PFQuery(className:"Contacts")
query.getObjectInBackgroundWithId(objectIDs[sender.tag]) {
(gameScore: PFObject!, error: NSError!) -> …Run Code Online (Sandbox Code Playgroud) 我想检测UITableViewCell上的按钮点击,其中父UITableView由多个部分组成.
在单节的情况下,我能够做到这一点,但是在确定有多个部分的正确部分时遇到了麻烦.
我试图确定用户点击按钮的UITableViewCell对应的正确部分.
以下是问题解决后的更新代码:
@property (strong, nonatomic) NSMutableArray* quantityArray;
@property (strong, nonatomic) NSMutableArray* rows;
@synthesize quantityArray,rows;
- (void)viewDidLoad {
[super viewDidLoad];
quantityArray = [[NSMutableArray alloc] init];
[self PluMinusFunction];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//
// Some code here.
//
if (addBtnClicked || minusBtnClicked) {
cell.lblCount.text = [[quantityArray objectAtIndex:indexPath.section-1]objectAtIndex:indexPath.row];
addBtnClicked = NO;
minusBtnClicked = NO;
} else {
cell.lblCount.text = [[quantityArray objectAtIndex:indexPath.section-1]objectAtIndex:indexPath.row];
}
cell.btnMinus.tag = indexPath.row;
cell.btnPlus.tag = indexPath.row;
cell.lblCount.tag = indexPath.row;
[cell.btnPlus addTarget:self action:@selector(addItem:) forControlEvents:UIControlEventTouchUpInside];
if ([ …Run Code Online (Sandbox Code Playgroud) 我想从自定义UITableViewCell中的按钮执行segue,但是当我按下该按钮时,我不知道如何访问单元格的内容.我意识到这可以通过didSelectRowAtIndexPath来完成,但是我有那个方法执行另一个函数,我想使用我在表格单元格中创建的按钮.
这是我的执行segue方法我遇到了麻烦:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "showComments"
{
let vc:CommentOnPostViewController = segue.destinationViewController as CommentOnPostViewController
var buttonPosition:CGPoint = sender?.convertPoint(CGPointZero, toView: self.feed) as CGPoint!
var path:NSIndexPath = self.feed.indexPathForRowAtPoint(buttonPosition) as NSIndexPath!
var postToCommentOn:PFObject = feedList[path.row] as PFObject
vc.post = postToCommentOn as PFObject
}
}
Run Code Online (Sandbox Code Playgroud)
我在显示单元格时标记按钮,并给它一个目标动作:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
// There is code that goes here for creating and displaying the cell.
cell.commentButton.tag = indexPath.row
cell.commentButton.addTarget(self, action: "addComment", forControlEvents: UIControlEvents.TouchUpInside)
}
Run Code Online (Sandbox Code Playgroud)
以下是按下按钮时调用的操作: …
我试图在用户点击表格视图中的表格视图单元格时将其带到新的视图控制器.更具体地说,当用户点击人员用户名时,它应该将他们带到该用户档案.用户名是表视图单元格,配置文件是新视图控制器.我认为这样做的方法是使用".presentViewController(vc,animated:true,completion:nil)"然而,当我这样做时,它说"myCell没有名为.presentViewController的成员"
如果有人能帮我解决这个问题,我将不胜感激
uitableview uiviewcontroller ios presentviewcontroller swift
我得到的UITutView属于UIButton属于这样:
-(void)buttonHandler:(UIButton *)button {
OrderCell *cell = [[button superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
Run Code Online (Sandbox Code Playgroud)
在iOS 7之前它可以正常工作.但是给了我:
[UITableViewCellScrollView item]:无法识别的选择器发送到实例0x17ae2cf0
如果我在iOS 7中运行该应用程序.但如果我这样做:
-(void)buttonHandler:(UIButton *)button {
OrderCell *cell = [[[button superview] superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
Run Code Online (Sandbox Code Playgroud)
然后它可以在iOS 7中运行,但不是更早???!?!
我这样做是在绕过这个问题:
OrderCell *cell;
if([[[UIDevice currentDevice] systemVersion] isEqualToString:@"7.0"])
cell = [[[button superview] superview] superview];
else
cell = [[button superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
Run Code Online (Sandbox Code Playgroud)
但是WTF还在继续!?有谁知道为什么会这样?
谢谢!
我最近下载了Swift 2附带的Xcode 7.以下是我尝试使用我的课程时遇到的错误 UITableViewDataSource,UITableViewDelegate它在Xcode 6.2中运行得非常好但在Xcode 7 beta 5中引发错误
class TableViewController: UITableViewController, UITableViewDataSource, UITableViewDelegate {
}
Run Code Online (Sandbox Code Playgroud)
//错误:'TableViewcontroller'与协议'UITableViewDataSource'的冗余一致性
我搜索谷歌的答案,但我无法得到它的解决方案.
我有一个UITableView设置了自定义单元格.每个单元都有一个开关,每次交换开关时我都需要获取特定单元的indexPath.每次切换交换机时,如何从UITableView返回单元格的indexPath和自定义单元格?
ios ×7
swift ×5
uitableview ×4
objective-c ×2
iphone ×1
parsing ×1
superview ×1
swift2 ×1
xcode7 ×1