我已经搜索过这个问题,但一无所获。我已经三次检查myTableView
是否与表格相关联,而在调用nil
时没有reloadData
,并且我正在为表格提供的新数组是新的而不是{{ 1}}。
但基本上,代码似乎有效。只是我需要关闭并重新打开要更新的表的视图。否则,当我点击一个应该更新表格的按钮时,它会变为空(直到我关闭并重新打开视图 - 然后我得到正确的数据)。
·H:
nil
.M
@interface AddressbookViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
IBOutlet UIButton * A;
IBOutlet UIButton * B;
IBOutlet UIButton * C;
IBOutlet UIButton * D;
IBOutlet UIButton * E;
IBOutlet UIButton * F;
IBOutlet UIButton * G;
IBOutlet UIButton * H;
IBOutlet UIButton * I;
IBOutlet UIButton * J;
IBOutlet UIButton * K;
IBOutlet UIButton * L;
IBOutlet UIButton * M;
IBOutlet UIButton * N;
IBOutlet UIButton * O;
IBOutlet UIButton * P;
IBOutlet UIButton * Q;
IBOutlet UIButton * R;
IBOutlet UIButton * S;
IBOutlet UIButton * T;
IBOutlet UIButton * U;
IBOutlet UIButton * V;
IBOutlet UIButton * W;
IBOutlet UIButton * X;
IBOutlet UIButton * Y;
IBOutlet UIButton * Z;
IBOutlet UIButton * vcCorp;
IBOutlet UIButton * vcLocal;
IBOutlet UIButton * listUp;
IBOutlet UIButton * listDown;
IBOutlet UIButton * close;
IBOutlet UIView *myView;
IBOutlet UITableView * myTableView;
NSMutableArray *tableArray;
CrestronClient * cClient;
CrestronControllerValues * CCV;
int viewOptions;
}
@property (nonatomic, retain) NSMutableArray *tableArray;
@property (nonatomic, retain) IBOutlet UITableView *myTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil type:(int)viewoptions;
@end
答案 0 :(得分:0)
从我发现它似乎
[tableArray removeAllObjects];
可能是我的问题。我认为这是一个计时问题,但即使在另一个线程上添加睡眠(1)后我的问题也没有解决。
这是工作代码。注意我改变了从删除所有对象到单独删除每个对象。
#import "AddressbookViewController.h"
#import "CrestronControllerValues.h"
@implementation AddressbookViewController
@synthesize myTableView,tableArray;
//viewOptions = 1=videoconferenceLOCAL 2=videoconferenceCORP 3=telepresence 4=audioconference
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil type:(int)viewoptions
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
viewOptions = 1;
viewOptions = viewoptions;
// tableArray = [[NSMutableArray alloc]initWithObjects:nil];
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidLoad
{
[super viewDidLoad];
CCV = [CrestronControllerValues sharedManager];
cClient = [CrestronClient sharedManager];
if (viewOptions == 1) {
[vcLocal setSelected:TRUE];
[vcCorp setSelected:FALSE];
}else if(viewOptions == 2){
[vcLocal setSelected:FALSE];
[vcCorp setSelected:TRUE];
}
if (viewOptions>2) {
A.hidden = true;
B.hidden = true;
C.hidden = true;
D.hidden = true;
E.hidden = true;
F.hidden = true;
G.hidden = true;
H.hidden = true;
I.hidden = true;
J.hidden = true;
K.hidden = true;
L.hidden = true;
M.hidden = true;
N.hidden = true;
O.hidden = true;
P.hidden = true;
Q.hidden = true;
R.hidden = true;
S.hidden = true;
T.hidden = true;
U.hidden = true;
V.hidden = true;
W.hidden = true;
X.hidden = true;
Y.hidden = true;
Z.hidden = true;
vcCorp.hidden = true;
vcLocal.hidden = true;
listUp.hidden = true;
listDown.hidden = true;
}
[A addTarget:self action:@selector(aPressed)
forControlEvents:UIControlEventTouchUpInside];
[B addTarget:self action:@selector(bPressed)
forControlEvents:UIControlEventTouchUpInside];
[C addTarget:self action:@selector(cPressed)
forControlEvents:UIControlEventTouchUpInside];
[D addTarget:self action:@selector(dPressed)
forControlEvents:UIControlEventTouchUpInside];
[E addTarget:self action:@selector(ePressed)
forControlEvents:UIControlEventTouchUpInside];
[F addTarget:self action:@selector(fPressed)
forControlEvents:UIControlEventTouchUpInside];
[G addTarget:self action:@selector(gPressed)
forControlEvents:UIControlEventTouchUpInside];
[H addTarget:self action:@selector(hPressed)
forControlEvents:UIControlEventTouchUpInside];
[I addTarget:self action:@selector(iPressed)
forControlEvents:UIControlEventTouchUpInside];
[J addTarget:self action:@selector(jPressed)
forControlEvents:UIControlEventTouchUpInside];
[K addTarget:self action:@selector(kPressed)
forControlEvents:UIControlEventTouchUpInside];
[L addTarget:self action:@selector(lPressed)
forControlEvents:UIControlEventTouchUpInside];
[M addTarget:self action:@selector(mPressed)
forControlEvents:UIControlEventTouchUpInside];
[N addTarget:self action:@selector(nPressed)
forControlEvents:UIControlEventTouchUpInside];
[O addTarget:self action:@selector(oPressed)
forControlEvents:UIControlEventTouchUpInside];
[P addTarget:self action:@selector(pPressed)
forControlEvents:UIControlEventTouchUpInside];
[Q addTarget:self action:@selector(qPressed)
forControlEvents:UIControlEventTouchUpInside];
[R addTarget:self action:@selector(rPressed)
forControlEvents:UIControlEventTouchUpInside];
[S addTarget:self action:@selector(sPressed)
forControlEvents:UIControlEventTouchUpInside];
[T addTarget:self action:@selector(tPressed)
forControlEvents:UIControlEventTouchUpInside];
[U addTarget:self action:@selector(uPressed)
forControlEvents:UIControlEventTouchUpInside];
[V addTarget:self action:@selector(vPressed)
forControlEvents:UIControlEventTouchUpInside];
[W addTarget:self action:@selector(wPressed)
forControlEvents:UIControlEventTouchUpInside];
[X addTarget:self action:@selector(xPressed)
forControlEvents:UIControlEventTouchUpInside];
[Y addTarget:self action:@selector(yPressed)
forControlEvents:UIControlEventTouchUpInside];
[Z addTarget:self action:@selector(zPressed)
forControlEvents:UIControlEventTouchUpInside];
[listUp addTarget:self action:@selector(listUpPressed)
forControlEvents:UIControlEventTouchUpInside];
[listDown addTarget:self action:@selector(listDownPressed)
forControlEvents:UIControlEventTouchUpInside];
[close addTarget:self action:@selector(closedPressed)
forControlEvents:UIControlEventTouchUpInside];
[vcCorp addTarget:self action:@selector(vcCorpPressed)
forControlEvents:UIControlEventTouchUpInside];
[vcLocal addTarget:self action:@selector(vcLocalPressed)
forControlEvents:UIControlEventTouchUpInside];
// Do any additional setup after loading the view from its nib.
switch (viewOptions) {
case 1:
[self setTableArray:CCV.currentPhonebookEntriesVideoChat];
break;
case 2:
[self setTableArray:CCV.currentPhonebookEntriesVideoChat];
break;
case 3:
[self setTableArray:CCV.currentPhonebookEntriesTelepresence];
break;
case 4:
[self setTableArray:CCV.currentPhonebookEntriesAudioChat];
break;
default:
[self setTableArray:CCV.currentPhonebookEntriesVideoChat];
break;
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int startCounter = 0;
switch (viewOptions) {
case 1:
startCounter = 308;
break;
case 2:
startCounter = 308;;
break;
case 3:
startCounter = 331;
break;
case 4:
startCounter = 286;
break;
default:
return nil;
break;
}
if ([[tableArray objectAtIndex:indexPath.row]isEqualToString:@"< empty >"]) {
NSLog(@"empty");
}else{
[cClient userDigitalPush:startCounter+indexPath.row];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [tableArray objectAtIndex:indexPath.row];
return cell;
}
-(void)setTableArray{
//[tableArray removeAllObjects];
//NSLog(@"set table array %@", CCV.currentPhonebookEntriesVideoChat);
int counter =0;
while ([tableArray count]>counter) {
[tableArray removeObjectAtIndex:counter];
counter++;
}
if (viewOptions == 1 || viewOptions == 2) {
tableArray =CCV.currentPhonebookEntriesVideoChat;
}else if(viewOptions == 3){
tableArray =CCV.currentPhonebookEntriesTelepresence;
}
//[self.myTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[[self myTableView] reloadData];
}
-(void)listUpPressed
{
//viewOptions = 1=videoconferenceLOCAL 2=videoconferenceCORP 3=telepresence 4=audioconference
int startCounter = 0;
switch (viewOptions) {
case 1:
startCounter = 318;
break;
case 2:
startCounter = 318;;
break;
case 3:
startCounter = 341;
break;
default:
return nil;
break;
}
[cClient userDigitalPush:startCounter];
[self setTableArray];
}
-(void)listDownPressed
{
int startCounter = 0;
switch (viewOptions) {
case 1:
startCounter = 318;
break;
case 2:
startCounter = 318;;
break;
case 3:
startCounter = 341;
break;
default:
return nil;
break;
}
[cClient userDigitalPush:startCounter+1];
NSLog(@"command sent");
[self setTableArray];
}
-(void)closedPressed
{
[self.view removeFromSuperview];
}
-(void)vcCorpPressed
{
[cClient userDigitalPush:326];
[vcLocal setSelected:FALSE];
[vcCorp setSelected:TRUE];
viewOptions = 2;
[self setTableArray];
}
-(void)vcLocalPressed
{
[cClient userDigitalPush:325];
[vcLocal setSelected:TRUE];
[vcCorp setSelected:FALSE];
viewOptions = 1;
[self setTableArray];
}
这是第二次removeallobjects没有按照我的预期工作。我要重新阅读文档,但我真的不明白为什么这是问题。我正在清理数组,将其设置为一个新数组,它仍然是空的