我有几个与UIColor和UIFont有关的问题.
我想知道如果我在启动时分配一堆UIFonts和UIColors,那么它在系统上有多重,我需要在应用程序运行期间.
在运行时创建UIFont和UIColor是否昂贵?如果我预先分配相同的内容,它会以任何方式提高性能.
假设您在重写的类中处理消息,例如:
class MailProcessorServer(smtpd.SMTPServer):
def process_message(self, peer, sender, rcpttos, data):
badrecipients = []
for rcpt in rcpttos:
badrecipients.append(rcpt)
#Here I want to warn the sender via a bounced email
# that the recipient does not exist
raise smtplib.SMTPRecipientsRefused(badrecipients)
#but this just crashes the process and eventually the sender times out,
# not good enough
Run Code Online (Sandbox Code Playgroud)
我只想立即回复发件人.相反,发送服务(比如GMail)最终会放弃,并在几小时后警告用户.该文件似乎很稀疏.
我正在解析XML并以Dictionary的形式将所有数据存储在NSMutableArray中.
NSMutableArray * stories;
// a temporary item; added to the "stories" array one at a time,
// and cleared for the next one
NSMutableDictionary * item;
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"item"])
{
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
//Numeric value for sorting
[item setObject:rates forKey:@"rates"];
[stories addObject:[item copy]];
}
}
Run Code Online (Sandbox Code Playgroud)
完成解析后,我需要按"rate"排序数组,这是数字字段.请建议.
我对以下行"静态NSString*MyIdentifier = @"MyIdentifier";"感到困惑 在方法中:cellForRowAtIndexPath
那条线做什么?它只是创建一个指向NSString对象的随机指针并为其分配字符串吗?为什么它被称为MyIdentifier,我在很多例子中都看到了这一点.
#import "AddToFavorites.h"
@implementation AddToFavorites
- (id)initWithStyle:(UITableViewStyle)style {
if (self = [super initWithStyle:style]) {
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier:MyIdentifier] autorelease];
}
// Configure the cell
return cell;
}
@end
Run Code Online (Sandbox Code Playgroud)
这是另一个例子,这个有一个不同的字符串CellIdentifier.
- (UITableViewCell *)tableView:(UITableView *)tableView …
Run Code Online (Sandbox Code Playgroud) cocoa-touch ×3
iphone ×3
objective-c ×2
cocoa ×1
email ×1
python ×1
smtp ×1
sorting ×1
uitableview ×1