我正在为我的网站开发一个应用程序,该应用程序具有带有解析器的 RSS 提要。我做了一个刷新按钮来查找新帖子,它可以工作。但是现在,如果没有找到新帖子,我希望它显示一个 UIAlertView,上面写着“未找到帖子”。
这是我的刷新按钮
- (IBAction)refreshButton:(UIBarButtonItem *)sender
{
// Create a new data container for the stuff that comes back from the service
xmlData = [[NSMutableData alloc] init];
// Construct a URL that will ask the service for what you want -
// Note we can concatenate literal strings together on multiple lines in this way it
// results in a single NSString instance
NSURL *url = [NSURL URLWithString:
@"http://sephardijews.com/feed/"];
// Putting the URL we made into an NSURLRequest, so we can connect to the url data that we specifed
NSURLRequest *req = [NSURLRequest requestWithURL:url];
// Creating a connecting that will exchange this request for the data from the URL we specifed
connection = [[NSURLConnection alloc] initWithRequest:req
delegate:self
startImmediately:YES];
[[self tableView] reloadData];
NSLog(@"%@\n %@\n %@\n", channel, [channel title], [channel infoString]);
}
我怎么能这样做?带有if语句的东西对吗?
刷新按钮:
- (IBAction)refreshButton:(UIBarButtonItem *)sender
{
// Create a new data container for the stuff that comes back from the service
xmlData = [[NSMutableData alloc] init];
// Construct a URL that will ask the service for what you want -
// Note we can concatenate literal strings together on multiple lines in this way it
// results in a single NSString instance
NSURL *url = [NSURL URLWithString:
@"http://sephardijews.com/feed/"];
// Putting the URL we made into an NSURLRequest, so we can connect to the url data that we specifed
NSURLRequest *req = [NSURLRequest requestWithURL:url];
// Creating a connecting that will exchange this request for the data from the URL we specifed
connection = [[NSURLConnection alloc] initWithRequest:req
delegate:self
startImmediately:YES];
[[self tableView] reloadData];
NSLog(@"%@\n %@\n %@\n", channel, [channel title], [channel infoString]);
if ([[self tableView] numberOfRowsInSection:0] > someNumberVariableForLastCount) {
someNumberVariableForLastCount = [[self tableView] numberOfRowsInSection:0];
[[self tableView] reloadData];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No New Posts" message:@"There were no new posts found" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[alert show];
}
}