所以項目組成員和我一直在分別研究我們的部件。我一直在研究應用程序中的一半視圖,並且他在另一半上工作。我把他的一半送給了他和他的一半,但當他試圖打開我的一半並運行它時,我們得到了不一致的結果。我們還沒有合併它們,所以它們不應該採取不同的行動。我試圖在其他幾臺電腦上測試它們,結果都一樣(與我的不同)。XCode在多臺計算機上的結果不一致
下面的代碼應該打印「CHECKED X」。 X表示在該點打勾的單元格的數量。在我的電腦上,它會打印「CHECKED 1..2..3..4」,您只能選擇最多4個,具體取決於打勾的數量。在任何其他計算機上,它會打印「CHECKED 0」,您可以隨心所欲地打勾(但不能取消打勾)。代碼滴答他們在這裏:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ((cell.accessoryType == UITableViewCellAccessoryNone) && [[DataContainerSingleton theDataContainerSingleton].favourites count] < 4 && ![self.tickedIndexPaths containsObject:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.tickedIndexPaths addObject:indexPath];
[[DataContainerSingleton theDataContainerSingleton].favourites addObject:[drinks objectAtIndex:indexPath.row]]; // DOES NOT ADD AN OBJECT?
NSLog(@"CHECKED %d", [[DataContainerSingleton theDataContainerSingleton].favourites count]);
}
else if (cell.accessoryType == UITableViewCellAccessoryCheckmark)
{
[self.tickedIndexPaths removeObject:indexPath];
for (int i = 0; i < [[DataContainerSingleton theDataContainerSingleton].favourites count]; i++)
{
NSString *drinkName = [[drinks objectAtIndex:indexPath.row] name];
NSString *favName = [[[DataContainerSingleton theDataContainerSingleton].favourites objectAtIndex:i] name];
if ([drinkName isEqualToString: favName])
{
cell.accessoryType = UITableViewCellAccessoryNone;
[[DataContainerSingleton theDataContainerSingleton].favourites removeObjectAtIndex:i];
NSLog(@"UNCHECKED %d", [[DataContainerSingleton theDataContainerSingleton].favourites count]);
}
}
}
}
在我看來,我的數據容器單身人士的收藏夾陣列似乎沒有被填補。飲料陣列不是空的。
下面是DataContainerSingleton類的代碼:
DataContainerSingleton.h
#import <Foundation/Foundation.h>
@interface DataContainerSingleton : NSObject
{
NSMutableArray *favourites;
NSMutableArray *drinks;
NSString *name;
int caffeine;
@private
}
@property (nonatomic, retain) NSMutableArray *favourites;
@property (nonatomic, retain) NSMutableArray *drinks;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, assign) int caffeine;
+ (DataContainerSingleton *) theDataContainerSingleton;
@end
DataContainerSingleton.m
#import "DataContainerSingleton.h"
@implementation DataContainerSingleton
@synthesize favourites, drinks;
@synthesize name, caffeine;
static DataContainerSingleton* _theDataContainerSingleton = nil;
+ (DataContainerSingleton*) theDataContainerSingleton;
{
if (!_theDataContainerSingleton)
_theDataContainerSingleton = [[DataContainerSingleton alloc] init];
return _theDataContainerSingleton;
}
- (id)init
{
self = [super init];
if (self)
{
self.favourites = [[[NSMutableArray alloc] init] autorelease];
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
@end
我已經檢查了所有的依賴在節目中,沒有任何的他們在我複製的文件夾之外。我清理並清理了構建文件夾,但它仍然打印0.
有沒有人有任何想法可能導致這種不一致?提前致謝。
第一個選項是不可能的,因爲它們是完全相同的副本。我有第二臺電腦,我現在正在測試它,它給我的結果與我現在使用的筆記本電腦不同。我直接複製它並打開了同一個文件的精確副本。我檢查了我的tableView的委託和數據源,他們都設置正確。 didSelectRowAtIndexPath方法實際上被調用,我用checpoint進行了檢查。 我打印出tickedIndexPaths每次我打電話上面的方法,它確實在4以上。 飲料數組被初始化。 – JheeBz