相关疑难解决方法(0)

单击UISwitch时选择UITableView的行

UITableViewUISwitchs他们在一起.

的TableView

当切换开关时,我想运行一个功能.该功能仅记录如果开关打开或关闭以及开关已更改的行.我遇到的问题是当我点击开关时它没有记录正确的行,除非我在单击开关之前点击了该行.

我想我的问题是单击开关不会选择行.如何才能选择行或者我可以将ID添加到交换机?

因此开关ID"1"为"ON".

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"POICell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


    //set the cell text to the catName
    cell.textLabel.text = [self.catNames objectAtIndex:[indexPath row]];
    //add switch 
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
    cell.accessoryView = switchView;
    [switchView setOn:YES animated:NO];

    [switchView addTarget:self action:@selector(switchChanged: ) forControlEvents:UIControlEventValueChanged];
    // Configure the cell...

    return cell;
}

     - (void) switchChanged:(id)sender {
            NSString *StrCatID =[[NSString alloc]init];
            StrCatID = [self.catIDs objectAtIndex:[self.inputTableView indexPathForSelectedRow].row];
            UISwitch* …
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c ios

5
推荐指数
4
解决办法
8003
查看次数

Switch中的TableView中的UISwitch

各位程序员大家好!我有一个需要帮助的挑战.我使用Custom Style Cell构建了一个表.

这个单元格只有一个LabelUISwitch.标签显示名称,交换机显示他们是否是管理员.这非常有效.我的挑战是如何以及在何处将代码置于更改开关时作出反应.

因此,如果我单击开关将其从关闭更改为打开,我可以在哪里打印人名?如果我可以得到打印的名称,我可以自己做php/sql代码.谢谢,这是我的代码片段.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as UITableViewCell
    let admin = self.admin[indexPath.row]

    let text1a = admin.FirstName
    let text1aa = " "

    let text1b = admin.LastName
    let text1 = text1a + text1aa + text1b
    (cell.contentView.viewWithTag(1) as UILabel).text = text1

    if admin.admin == "yes" {
        (cell.contentView.viewWithTag(2) as UISwitch).setOn(true, animated:true)

    } else if admin.admin == "no" {
        (cell.contentView.viewWithTag(2) as UISwitch).setOn(false, animated:true)
    }

    return cell
}
Run Code Online (Sandbox Code Playgroud)

tableview uiswitch swift

4
推荐指数
1
解决办法
8013
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1

swift ×1

tableview ×1

uiswitch ×1

xcode ×1