我使用此代码比较两个NSNumber对象,但它从未传递if条件.
listItems = [appDelegate.productStatus componentsSeparatedByString:@","];
for (int i=0;i<[appDelegate.productArray count]; i++)
{
for (int j=0; j<[listItems count]; j++)
{
number=[NSNumber numberWithInt:[[listItems objectAtIndex:j] intValue]];
NSLog(@"number %@",number);
productObject=[appDelegate.productArray objectAtIndex:i];
NSLog(@"%@,%@",productObject.pid,number);
if (productObject.pid == number)
{
NSLog(@"BUY it!!!");
[purchasArray addObject:productObject];
}
}
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
在我的应用程序中,我有一个imageView和一个UILabel.对于ImageView,我已经为它分配了asynch Image并且它工作正常,但是当我滚动表时,第一行和最后一行的标签重叠.
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
productObject=[appDelegate.productArray objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *nameLabel;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
else
{
AsyncImageView* oldImage = (AsyncImageView*)[cell.contentView viewWithTag:999];
[oldImage removeFromSuperview];
}
CGRect nameLabelRect = CGRectMake(70,80,150,15);
nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];
nameLabel.text = [NSString stringWithFormat:@"%@",productObject.productname];
nameLabel.textAlignment = UITextAlignmentCenter;
nameLabel.lineBreakMode = UILineBreakModeCharacterWrap;
nameLabel.font = [UIFont boldSystemFontOfSize:15];
nameLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: nameLabel]; …Run Code Online (Sandbox Code Playgroud)