Я разрабатываю приложение для своего сайта, на котором есть RSS-канал с парсером. Я сделал кнопку обновления, чтобы искать новые сообщения, и это работает. Но теперь я хочу, чтобы он отображал UIAlertView, в котором говорится «Нет сообщений», если не было обнаружено новых сообщений.Показать 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];
}
}
[? Что вы пробовали] (http://mattgemmell.com/2008/12/ 08/what-have-you-try /) –