我试图寻找答案,但没有成功。
我想在其中一个UILabel中传递文本。我不完全确定如何做到这一点。我试图将其中一个UILabel的内容传递给swipeTableViewCell didTriggerRightUtilityWithIndex函数,因为我正在使用SWTableViewCell。
该表填充了mysql表中的项目。
这是我目前的UITableViewCell功能:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
if([taskArray valueForKey:@"TaskData"] != [NSNull null])
{
GroupDataTableViewCell *cell = (GroupDataTableViewCell*)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Add utility buttons
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]
title:@"Les mer"];
cell.rightUtilityButtons = rightUtilityButtons;
cell.delegate = self;
if (cell == nil) {
//cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableItem" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSDictionary *item = [taskArray objectAtIndex:indexPath.row];
if([item objectForKey:@"TaskID"] != [NSNull null])
cell.numberTextField.text = [item objectForKey:@"TaskID"];
if([item objectForKey:@"Title"] != [NSNull null])
cell.titleTextField.text = [item objectForKey:@"Title"];
if([item objectForKey:@"Description"] != [NSNull null])
cell.descriptionTextField.text = [item objectForKey:@"Description"];
if([[selfArray valueForKey:@"CheckStat"] isEqualToString:@"(null)"])
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else if([[selfArray valueForKey:@"CheckStat"] length] == 0)
{
if ([[item objectForKey:@"CheckStat"] containsString:@"1"])
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
for(int i = 0; i < [[[selfArray valueForKey:@"CheckStat"] componentsSeparatedByString:@","] count]; i++)
{
NSString *checkedNumStr = [[[selfArray valueForKey:@"CheckStat"] componentsSeparatedByString:@","] objectAtIndex:i];
//if (i >= [taskArray count] || [checkedNumStr intValue] >= [taskArray count])
//break;
if ([checkedNumStr intValue] == indexPath.row + 1)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
return cell;
}
else
return nil;
}
当要激活rightUtilityButton时,我想将cell.descriptionField.text从那里发送到此代码:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
switch (index) {
case 0:
{
// More button is pressed
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Bookmark" message:@"Description" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
[cell hideUtilityButtonsAnimated:YES];
break;
}
case 1:
default:
break;
}
}
所以,我希望将第一个代码段中的cell.descriptionTextField.text转换为第二个代码段。我不完全确定如何做到这一点,因为我对tablecells并不擅长。我希望第一个代码段中的cell.descriptionTextField.text在alertView中显示为描述。
答案 0 :(得分:2)
将[item objectForKey:@“Description”]保存到以前创建的NSMutableArray中,如果您按照与nsmutablearray相同的顺序订购单元格,则可以将此值访问到您想要的函数中,如下所示:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
switch (index) {
case 0:
{
// More button is pressed
NSString *desc = [myarray objectAtIndex:index];
// Use your string wherever you want
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Bookmark" message:@"Description" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
[cell hideUtilityButtonsAnimated:YES];
break;
}
case 1:
default:
break;
}
}
答案 1 :(得分:0)
为什么不将这些文本存储在类中的NSString *属性中,然后在需要的地方使用?
答案 2 :(得分:-1)
不要将信息存储在单元格对象中,而不是使用数据源来存储信息。 使用索引,您可以获得存储在标签
中的相应信息在您的情况下,您将描述存储在标签中,以后可以按如下方式检索
-(void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index
{
NSDictionary *item = [taskArray objectAtIndex:index;
//Do something with the item
}