嗨,伙计,我试图隐藏第1节(第二部分)中的一些行,这取决于用户选择了哪种类型的反馈:
我正在使用静态单元格,但是当我选择TypeVC中的一个选项时,没有删除任何内容。目前没有错误,但猜测一下,我认为这与我在switch语句中使用的逻辑运算符有关。很抱歉抛出了我的代码,但由于我对IOS非常陌生,我不知道你们到底需要看到什么。
1
if (variable == (1|2|3)){} 我已经习惯了Java,而且我经常使用这种友好的语句,因为它节省了写作。在目标C中是这样做的吗?
2
我在哪里,怎么搞错了,试图让这些细胞去分解?
FeedbackTableViewController:
#import "FeedbackTableViewController.h"
#import "TypeTableViewController.h"
@interface FeedbackTableViewController ()
@property NSInteger index;
@end
@implementation FeedbackTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated{
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSIndexPath *) tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Type: %i",_type);
if (indexPath.section == 0 && indexPath.row == 0)
[self performSegueWithIdentifier:@"showTypeVC" sender:self];
return indexPath;
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
TypeTableViewController *tvc = [segue destinationViewController];
tvc.indexchoosen = _index;
}
//- (UITableViewCell *)tableView:(UITableView *)tableView
// cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//
// UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
//
// if (indexPath.row==0) cell.textLabel.text = _typeString;
// else if (indexPath.row)
//
// return cell;
//}
- (CGFloat) tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"section: %i row:%i",indexPath.section, indexPath.row);
if (indexPath.section == 1) {
switch (_type) {
case 0:
if (indexPath.row==(2|3|4))return 0;
break;
case 1:
if (indexPath.row==(0|1|4))return 0;
break;
case 2:
if (indexPath.row==(0|1|2|3))return 0;
break;
case 3:
return 0;
break;
case 4:
return 0;
break;
case 5:
return 0;
break;
default:
return 0;
break;
}
}
return 43;
}
- (IBAction)unwindtypeVC:(UIStoryboardSegue *)segue { }
@endTypeTableViewController:
#import "TypeTableViewController.h"
#import "FeedbackTableViewController.h"
@interface TypeTableViewController ()
@end
@implementation TypeTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_typeoptions = @[@"Routing Issues",
@"Wrongly Labelled Location",
@"Missing Location",
@"Comment on Useability",
@"Suggestions",
@"General Feedback"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 6;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = self.typeoptions[indexPath.row];
return cell;
}
- (NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
_indexchoosen = indexPath.row;
return indexPath;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSString *string = _typeoptions[_indexchoosen];
FeedbackTableViewController *fvc1 = [segue destinationViewController];
fvc1.typeString.text = _typeoptions[_indexchoosen];
fvc1.type = _indexchoosen;
}
@end对于实现我想要达到的目标,我愿意接受更好的想法,所以如果你考虑告诉我一种更有效的方法,我将非常感激。我知道代表们可能是一种选择,但我对他们还没有信心,我会认为这对我来说更容易。
发布于 2014-08-01 11:09:18
实际上,我使用了将行高更改为0的方法。
为了有效地做到这一点,我必须删除占位符/我不想显示的行中的任何初始文本。这需要一些故事板连接,您将看到这些连接被命名为_feedbackText、_startLocation等。当用户选择一个新行时,它们将对原始反馈表单执行一个segue,因此调用viewDidAppear。我用这个来调用self.tableView reloadData。最初,变量_type中的更改实际上不会改变任何东西,但是在重新加载数据时会召回heightForRowAtIndexPath。
我确信在indexPath上使用delete行也是有效的,但是我想存储用户在更改反馈类型之前可能输入的信息。
新方法:
- (CGFloat) tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSInteger i = indexPath.row;
if (indexPath.section == 1) {
switch (_type) {
case 0:
_startLocation.placeholder = @"Start Location:";
_destination.placeholder = @"Destination:";
_locationName.placeholder = @"";
_correctName.placeholder = @"";
_missingLocation.placeholder = @"";
if (i==2||i==3||i==4) return 0;
break;
case 1:
_startLocation.placeholder = @"";
_destination.placeholder = @"";
_locationName.placeholder = @"Location Name:";
_correctName.placeholder = @"Correct Name:";
_missingLocation.placeholder = @"";
if (i==0||i==1||i==4)return 0;
break;
case 2:
_startLocation.placeholder = @"";
_destination.placeholder = @"";
_locationName.placeholder = @"";
_correctName.placeholder = @"";
_missingLocation.placeholder = @"Missing Location:";
if (i==0||i==1||i==2||i==3)return 0;
break;
case 3:
return 0;
break;
case 4:
return 0;
break;
case 5:
return 0;
break;
default:
_startLocation.placeholder = @"";
_destination.placeholder = @"";
_locationName.placeholder = @"";
_correctName.placeholder = @"";
_missingLocation.placeholder = @"";
if (i==0||i==1||i==2||i==3||i==4)return 0;
break;
}
} else if (indexPath.section==2 && indexPath.row==2) return 240;
else if (indexPath.section==0 && indexPath.row==0) return 40;
return 30;
}这将本质上隐藏,但不会删除文本字段中的信息。如果您想保存用户输入的任何信息,这非常有用。
我希望这有助于任何试图在分组静态表视图控制器中隐藏行的人。
发布于 2014-07-31 12:54:31
对于1,试试这个,自己看看:
int test = 3;
if(test == (1 | 2))
NSLog(@"_MEH_");由于它是位或运算,0010 \ 0001等于0011,等于3。因此,我建议您不要使用这样的操作。(当然,如果这不是有意的话)。
对于2,您应该使用删除deleteRowsAtIndexPaths:WwithRow动画: call For UITableView来删除行。
例如;
[self.tableView beginUpdates];
NSIndexPath* rowToDelete = [NSIndexPath indexPathForRow:0 inSection:0]; // For showing purposes only.
NSArray* indexArray = [NSArray arrayWithObjects:rowToDelete, nil];
[self.tableView deleteRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationMiddle];
[self.tableView endUpdates];另外,不要忘记相应地更新数据源。您可能需要将一些对象从
self.typeoptions阵列。
P.S:另外,您还应该更改tableView:numberOfRowsInSection:因为行数将少于6。
https://stackoverflow.com/questions/25057764
复制相似问题